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

pull/362/head
Guo, Yejun 4 years ago
parent cde6d0288f
commit 4c705a2775
  1. 2
      libavfilter/dnn/dnn_backend_native.c
  2. 6
      libavfilter/dnn/dnn_backend_openvino.c
  3. 12
      libavfilter/dnn/dnn_backend_tf.c
  4. 18
      libavfilter/dnn/dnn_io_proc.c
  5. 3
      libavfilter/dnn/dnn_io_proc.h

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

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

@ -763,12 +763,22 @@ static DNNReturnType execute_model_tf(const DNNModel *model, const char *input_n
} }
input.data = (float *)TF_TensorData(input_tensor); input.data = (float *)TF_TensorData(input_tensor);
switch (tf_model->model->func_type) {
case DFT_PROCESS_FRAME:
if (do_ioproc) { if (do_ioproc) {
if (tf_model->model->frame_pre_proc != NULL) { if (tf_model->model->frame_pre_proc != NULL) {
tf_model->model->frame_pre_proc(in_frame, &input, tf_model->model->filter_ctx); tf_model->model->frame_pre_proc(in_frame, &input, tf_model->model->filter_ctx);
} else { } else {
ff_proc_from_frame_to_dnn(in_frame, &input, tf_model->model->func_type, ctx); 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)); tf_outputs = av_malloc_array(nb_output, sizeof(*tf_outputs));

@ -97,7 +97,7 @@ DNNReturnType ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *l
return DNN_SUCCESS; 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; struct SwsContext *sws_ctx;
int bytewidth = av_image_get_linesize(frame->format, frame->width, 0); 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; 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; struct SwsContext *sws_ctx;
int linesizes[4]; int linesizes[4];
@ -277,17 +277,3 @@ static DNNReturnType proc_from_frame_to_dnn_analytics(AVFrame *frame, DNNData *i
sws_freeContext(sws_ctx); sws_freeContext(sws_ctx);
return DNN_SUCCESS; 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;
}
}

@ -30,8 +30,9 @@
#include "../dnn_interface.h" #include "../dnn_interface.h"
#include "libavutil/frame.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_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); DNNReturnType ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t bbox_index, void *log_ctx);
#endif #endif

Loading…
Cancel
Save