summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuo, Yejun <yejun.guo@intel.com>2021-05-17 10:31:16 +0800
committerGuo, Yejun <yejun.guo@intel.com>2021-05-24 09:09:34 +0800
commit4c705a2775afca7eadc40835bfaafb29a9c5c38a (patch)
tree5c62ca48eb87c7140072e0734ac4dc3d6cb4c38b
parentcde6d0288fc9bd2238b5078b4d998569ba65b2b7 (diff)
lavfi/dnn: refine code to separate processing and detection in backends
-rw-r--r--libavfilter/dnn/dnn_backend_native.c2
-rw-r--r--libavfilter/dnn/dnn_backend_openvino.c6
-rw-r--r--libavfilter/dnn/dnn_backend_tf.c20
-rw-r--r--libavfilter/dnn/dnn_io_proc.c18
-rw-r--r--libavfilter/dnn/dnn_io_proc.h3
5 files changed, 24 insertions, 25 deletions
diff --git a/libavfilter/dnn/dnn_backend_native.c b/libavfilter/dnn/dnn_backend_native.c
index b5f1c16538..a6be27f1fd 100644
--- a/libavfilter/dnn/dnn_backend_native.c
+++ b/libavfilter/dnn/dnn_backend_native.c
@@ -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);
}
}
diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c
index 1ff8a720b9..e0781e854a 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -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;
diff --git a/libavfilter/dnn/dnn_backend_tf.c b/libavfilter/dnn/dnn_backend_tf.c
index 5908aeb359..4c16c2bdb0 100644
--- a/libavfilter/dnn/dnn_backend_tf.c
+++ b/libavfilter/dnn/dnn_backend_tf.c
@@ -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));
diff --git a/libavfilter/dnn/dnn_io_proc.c b/libavfilter/dnn/dnn_io_proc.c
index 02c8e13ed7..021d004e1d 100644
--- a/libavfilter/dnn/dnn_io_proc.c
+++ b/libavfilter/dnn/dnn_io_proc.c
@@ -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;
- }
-}
diff --git a/libavfilter/dnn/dnn_io_proc.h b/libavfilter/dnn/dnn_io_proc.h
index 16dcdd6d1a..daef01aceb 100644
--- a/libavfilter/dnn/dnn_io_proc.h
+++ b/libavfilter/dnn/dnn_io_proc.h
@@ -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