]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/dnn/dnn_backend_openvino.c
lavfi/dnn_backend_openvino.c: Spelling Correction in OpenVino Backend
[ffmpeg] / libavfilter / dnn / dnn_backend_openvino.c
index 50de6a996e8628eca67800d315cb4373c130cc10..a8032fe56bbb210981bf77c6c09e3b2dd6b3f2b0 100644 (file)
@@ -166,8 +166,8 @@ static DNNReturnType fill_model_input_ov(OVModel *ov_model, RequestItem *request
     for (int i = 0; i < request->task_count; ++i) {
         task = request->tasks[i];
         if (task->do_ioproc) {
-            if (ov_model->model->pre_proc != NULL) {
-                ov_model->model->pre_proc(task->in_frame, &input, ov_model->model->filter_ctx);
+            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);
             }
@@ -236,16 +236,32 @@ static void infer_completion_callback(void *args)
     av_assert0(request->task_count >= 1);
     for (int i = 0; i < request->task_count; ++i) {
         task = request->tasks[i];
-        if (task->do_ioproc) {
-            if (task->ov_model->model->post_proc != NULL) {
-                task->ov_model->model->post_proc(task->out_frame, &output, task->ov_model->model->filter_ctx);
+
+        switch (task->ov_model->model->func_type) {
+        case DFT_PROCESS_FRAME:
+            if (task->do_ioproc) {
+                if (task->ov_model->model->frame_post_proc != NULL) {
+                    task->ov_model->model->frame_post_proc(task->out_frame, &output, task->ov_model->model->filter_ctx);
+                } else {
+                    ff_proc_from_dnn_to_frame(task->out_frame, &output, ctx);
+                }
             } else {
-                ff_proc_from_dnn_to_frame(task->out_frame, &output, ctx);
+                task->out_frame->width = output.width;
+                task->out_frame->height = output.height;
             }
-        } else {
-            task->out_frame->width = output.width;
-            task->out_frame->height = output.height;
+            break;
+        case DFT_ANALYTICS_DETECT:
+            if (!task->ov_model->model->detect_post_proc) {
+                av_log(ctx, AV_LOG_ERROR, "detect filter needs to provide post proc\n");
+                return;
+            }
+            task->ov_model->model->detect_post_proc(task->out_frame, &output, 1, task->ov_model->model->filter_ctx);
+            break;
+        default:
+            av_assert0(!"should not reach here");
+            break;
         }
+
         task->done = 1;
         output.data = (uint8_t *)output.data
                       + output.width * output.height * output.channels * get_datatype_size(output.dt);
@@ -302,7 +318,7 @@ static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, co
     }
 
     // all models in openvino open model zoo use BGR with range [0.0f, 255.0f] as input,
-    // we don't have a AVPixelFormat to descibe it, so we'll use AV_PIX_FMT_BGR24 and
+    // we don't have a AVPixelFormat to describe it, so we'll use AV_PIX_FMT_BGR24 and
     // ask openvino to do the conversion internally.
     // the current supported SR model (frame processing) is generated from tensorflow model,
     // and its input is Y channel as float with range [0.0f, 1.0f], so do not set for this case.
@@ -353,25 +369,23 @@ static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, co
             goto err;
         }
 
+        item->callback.completeCallBackFunc = infer_completion_callback;
+        item->callback.args = item;
+        if (ff_safe_queue_push_back(ov_model->request_queue, item) < 0) {
+            av_freep(&item);
+            goto err;
+        }
+
         status = ie_exec_network_create_infer_request(ov_model->exe_network, &item->infer_request);
         if (status != OK) {
-            av_freep(&item);
             goto err;
         }
 
         item->tasks = av_malloc_array(ctx->options.batch_size, sizeof(*item->tasks));
         if (!item->tasks) {
-            av_freep(&item);
             goto err;
         }
         item->task_count = 0;
-
-        item->callback.completeCallBackFunc = infer_completion_callback;
-        item->callback.args = item;
-        if (ff_safe_queue_push_back(ov_model->request_queue, item) < 0) {
-            av_freep(&item);
-            goto err;
-        }
     }
 
     ov_model->task_queue = ff_queue_create();
@@ -495,6 +509,11 @@ static DNNReturnType get_output_ov(void *model, const char *input_name, int inpu
     IEStatusCode status;
     input_shapes_t input_shapes;
 
+    if (ov_model->model->func_type != DFT_PROCESS_FRAME) {
+        av_log(ctx, AV_LOG_ERROR, "Get output dim only when processing frame.\n");
+        return DNN_ERROR;
+    }
+
     if (ctx->options.input_resizable) {
         status = ie_network_get_input_shapes(ov_model->network, &input_shapes);
         input_shapes.shapes->shape.dims[2] = input_height;
@@ -680,12 +699,6 @@ DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, const char *i
         return DNN_ERROR;
     }
 
-    task = av_malloc(sizeof(*task));
-    if (!task) {
-        av_log(ctx, AV_LOG_ERROR, "unable to alloc memory for task item.\n");
-        return DNN_ERROR;
-    }
-
     if (!ov_model->exe_network) {
         if (init_model_ov(ov_model, input_name, output_names[0]) != DNN_SUCCESS) {
             av_log(ctx, AV_LOG_ERROR, "Failed init OpenVINO exectuable network or inference request\n");
@@ -693,6 +706,12 @@ DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, const char *i
         }
     }
 
+    task = av_malloc(sizeof(*task));
+    if (!task) {
+        av_log(ctx, AV_LOG_ERROR, "unable to alloc memory for task item.\n");
+        return DNN_ERROR;
+    }
+
     task->done = 0;
     task->do_ioproc = 1;
     task->async = 1;