diff options
author | Guo, Yejun <yejun.guo@intel.com> | 2020-09-10 22:29:57 +0800 |
---|---|---|
committer | Guo, Yejun <yejun.guo@intel.com> | 2020-09-21 21:26:56 +0800 |
commit | fce3e3e137843d86411f8868f18e1c3f472de0e5 (patch) | |
tree | 4ad669abc4ea7fc78220f4b24f0455fb17a8234b /libavfilter/vf_dnn_processing.c | |
parent | 2003e32f62d94ba75b59d70632c9f2862b383591 (diff) |
dnn: put DNNModel.set_input and DNNModule.execute_model together
suppose we have a detect and classify filter in the future, the
detect filter generates some bounding boxes (BBox) as AVFrame sidedata,
and the classify filter executes DNN model for each BBox. For each
BBox, we need to crop the AVFrame, copy data to DNN model input and do
the model execution. So we have to save the in_frame at DNNModel.set_input
and use it at DNNModule.execute_model, such saving is not feasible
when we support async execute_model.
This patch sets the in_frame as execution_model parameter, and so
all the information are put together within the same function for
each inference. It also makes easy to support BBox async inference.
Diffstat (limited to 'libavfilter/vf_dnn_processing.c')
-rw-r--r-- | libavfilter/vf_dnn_processing.c | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/libavfilter/vf_dnn_processing.c b/libavfilter/vf_dnn_processing.c index d7462bc828..2c8578c9b0 100644 --- a/libavfilter/vf_dnn_processing.c +++ b/libavfilter/vf_dnn_processing.c @@ -236,15 +236,11 @@ static int config_output(AVFilterLink *outlink) AVFrame *out = NULL; AVFrame *fake_in = ff_get_video_buffer(inlink, inlink->w, inlink->h); - result = (ctx->model->set_input)(ctx->model->model, fake_in, ctx->model_inputname); - if (result != DNN_SUCCESS) { - av_log(ctx, AV_LOG_ERROR, "could not set input for the model\n"); - return AVERROR(EIO); - } // have a try run in case that the dnn model resize the frame out = ff_get_video_buffer(inlink, inlink->w, inlink->h); - result = (ctx->dnn_module->execute_model)(ctx->model, (const char **)&ctx->model_outputname, 1, out); + result = (ctx->dnn_module->execute_model)(ctx->model, ctx->model_inputname, fake_in, + (const char **)&ctx->model_outputname, 1, out); if (result != DNN_SUCCESS){ av_log(ctx, AV_LOG_ERROR, "failed to execute model\n"); return AVERROR(EIO); @@ -293,13 +289,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) DNNReturnType dnn_result; AVFrame *out; - dnn_result = (ctx->model->set_input)(ctx->model->model, in, ctx->model_inputname); - if (dnn_result != DNN_SUCCESS) { - av_log(ctx, AV_LOG_ERROR, "could not set input for the model\n"); - av_frame_free(&in); - return AVERROR(EIO); - } - out = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!out) { av_frame_free(&in); @@ -307,7 +296,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) } av_frame_copy_props(out, in); - dnn_result = (ctx->dnn_module->execute_model)(ctx->model, (const char **)&ctx->model_outputname, 1, out); + dnn_result = (ctx->dnn_module->execute_model)(ctx->model, ctx->model_inputname, in, + (const char **)&ctx->model_outputname, 1, out); if (dnn_result != DNN_SUCCESS){ av_log(ctx, AV_LOG_ERROR, "failed to execute model\n"); av_frame_free(&in); |