lavfi/dnn: refine code to separate processing and detection in backends

This commit is contained in:
Guo, Yejun 2021-05-17 10:31:16 +08:00
parent cde6d0288f
commit 4c705a2775
5 changed files with 24 additions and 25 deletions

View File

@ -314,7 +314,7 @@ static DNNReturnType execute_model_native(const DNNModel *model, const char *inp
if (native_model->model->frame_pre_proc != NULL) {
native_model->model->frame_pre_proc(in_frame, &input, native_model->model->filter_ctx);
} else {
ff_proc_from_frame_to_dnn(in_frame, &input, native_model->model->func_type, ctx);
ff_proc_from_frame_to_dnn(in_frame, &input, ctx);
}
}

View File

@ -186,15 +186,17 @@ static DNNReturnType fill_model_input_ov(OVModel *ov_model, RequestItem *request
task = inference->task;
switch (task->ov_model->model->func_type) {
case DFT_PROCESS_FRAME:
case DFT_ANALYTICS_DETECT:
if (task->do_ioproc) {
if (ov_model->model->frame_pre_proc != NULL) {
ov_model->model->frame_pre_proc(task->in_frame, &input, ov_model->model->filter_ctx);
} else {
ff_proc_from_frame_to_dnn(task->in_frame, &input, ov_model->model->func_type, ctx);
ff_proc_from_frame_to_dnn(task->in_frame, &input, ctx);
}
}
break;
case DFT_ANALYTICS_DETECT:
ff_frame_to_dnn_detect(task->in_frame, &input, ctx);
break;
case DFT_ANALYTICS_CLASSIFY:
ff_frame_to_dnn_classify(task->in_frame, &input, inference->bbox_index, ctx);
break;

View File

@ -763,12 +763,22 @@ static DNNReturnType execute_model_tf(const DNNModel *model, const char *input_n
}
input.data = (float *)TF_TensorData(input_tensor);
if (do_ioproc) {
if (tf_model->model->frame_pre_proc != NULL) {
tf_model->model->frame_pre_proc(in_frame, &input, tf_model->model->filter_ctx);
} else {
ff_proc_from_frame_to_dnn(in_frame, &input, tf_model->model->func_type, ctx);
switch (tf_model->model->func_type) {
case DFT_PROCESS_FRAME:
if (do_ioproc) {
if (tf_model->model->frame_pre_proc != NULL) {
tf_model->model->frame_pre_proc(in_frame, &input, tf_model->model->filter_ctx);
} else {
ff_proc_from_frame_to_dnn(in_frame, &input, ctx);
}
}
break;
case DFT_ANALYTICS_DETECT:
ff_frame_to_dnn_detect(in_frame, &input, ctx);
break;
default:
avpriv_report_missing_feature(ctx, "model function type %d", tf_model->model->func_type);
break;
}
tf_outputs = av_malloc_array(nb_output, sizeof(*tf_outputs));

View File

@ -97,7 +97,7 @@ DNNReturnType ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *l
return DNN_SUCCESS;
}
static DNNReturnType proc_from_frame_to_dnn_frameprocessing(AVFrame *frame, DNNData *input, void *log_ctx)
DNNReturnType ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx)
{
struct SwsContext *sws_ctx;
int bytewidth = av_image_get_linesize(frame->format, frame->width, 0);
@ -249,7 +249,7 @@ DNNReturnType ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t
return DNN_SUCCESS;
}
static DNNReturnType proc_from_frame_to_dnn_analytics(AVFrame *frame, DNNData *input, void *log_ctx)
DNNReturnType ff_frame_to_dnn_detect(AVFrame *frame, DNNData *input, void *log_ctx)
{
struct SwsContext *sws_ctx;
int linesizes[4];
@ -277,17 +277,3 @@ static DNNReturnType proc_from_frame_to_dnn_analytics(AVFrame *frame, DNNData *i
sws_freeContext(sws_ctx);
return DNN_SUCCESS;
}
DNNReturnType ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, DNNFunctionType func_type, void *log_ctx)
{
switch (func_type)
{
case DFT_PROCESS_FRAME:
return proc_from_frame_to_dnn_frameprocessing(frame, input, log_ctx);
case DFT_ANALYTICS_DETECT:
return proc_from_frame_to_dnn_analytics(frame, input, log_ctx);
default:
avpriv_report_missing_feature(log_ctx, "model function type %d", func_type);
return DNN_ERROR;
}
}

View File

@ -30,8 +30,9 @@
#include "../dnn_interface.h"
#include "libavutil/frame.h"
DNNReturnType ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, DNNFunctionType func_type, void *log_ctx);
DNNReturnType ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx);
DNNReturnType ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx);
DNNReturnType ff_frame_to_dnn_detect(AVFrame *frame, DNNData *input, void *log_ctx);
DNNReturnType ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t bbox_index, void *log_ctx);
#endif