From: wenbin.chen-at-intel.com@ffmpeg.org To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 2/4] libavfilter/vf_dnn_detect: Add input pad Date: Mon, 4 Dec 2023 13:36:31 +0800 Message-ID: <20231204053633.1743228-2-wenbin.chen@intel.com> (raw) In-Reply-To: <20231204053633.1743228-1-wenbin.chen@intel.com> From: Wenbin Chen <wenbin.chen@intel.com> Add input pad to get model input resolution. Detection models always have fixed input size. And the output coordinators are based on the input resolution, so we need to get input size to map coordinators to our real output frames. Signed-off-by: Wenbin Chen <wenbin.chen@intel.com> --- libavfilter/dnn/dnn_backend_openvino.c | 24 ++++++++++++++++------ libavfilter/vf_dnn_detect.c | 28 +++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c index 089e028818..671a995c70 100644 --- a/libavfilter/dnn/dnn_backend_openvino.c +++ b/libavfilter/dnn/dnn_backend_openvino.c @@ -1073,9 +1073,15 @@ static int get_input_ov(void *model, DNNData *input, const char *input_name) return AVERROR(ENOSYS); } - input->channels = dims[1]; - input->height = input_resizable ? -1 : dims[2]; - input->width = input_resizable ? -1 : dims[3]; + if (dims[1] <= 3) { // NCHW + input->channels = dims[1]; + input->height = input_resizable ? -1 : dims[2]; + input->width = input_resizable ? -1 : dims[3]; + } else { // NHWC + input->height = input_resizable ? -1 : dims[1]; + input->width = input_resizable ? -1 : dims[2]; + input->channels = dims[3]; + } input->dt = precision_to_datatype(precision); return 0; @@ -1105,9 +1111,15 @@ static int get_input_ov(void *model, DNNData *input, const char *input_name) return DNN_GENERIC_ERROR; } - input->channels = dims.dims[1]; - input->height = input_resizable ? -1 : dims.dims[2]; - input->width = input_resizable ? -1 : dims.dims[3]; + if (dims[1] <= 3) { // NCHW + input->channels = dims[1]; + input->height = input_resizable ? -1 : dims[2]; + input->width = input_resizable ? -1 : dims[3]; + } else { // NHWC + input->height = input_resizable ? -1 : dims[1]; + input->width = input_resizable ? -1 : dims[2]; + input->channels = dims[3]; + } input->dt = precision_to_datatype(precision); return 0; } diff --git a/libavfilter/vf_dnn_detect.c b/libavfilter/vf_dnn_detect.c index 373dda58bf..86f61c9907 100644 --- a/libavfilter/vf_dnn_detect.c +++ b/libavfilter/vf_dnn_detect.c @@ -699,13 +699,39 @@ static av_cold void dnn_detect_uninit(AVFilterContext *context) free_detect_labels(ctx); } +static int config_input(AVFilterLink *inlink) +{ + AVFilterContext *context = inlink->dst; + DnnDetectContext *ctx = context->priv; + DNNData model_input; + int ret; + + ret = ff_dnn_get_input(&ctx->dnnctx, &model_input); + if (ret != 0) { + av_log(ctx, AV_LOG_ERROR, "could not get input from the model\n"); + return ret; + } + ctx->scale_width = model_input.width == -1 ? inlink->w : model_input.width; + ctx->scale_height = model_input.height == -1 ? inlink->h : model_input.height; + + return 0; +} + +static const AVFilterPad dnn_detect_inputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_input, + }, +}; + const AVFilter ff_vf_dnn_detect = { .name = "dnn_detect", .description = NULL_IF_CONFIG_SMALL("Apply DNN detect filter to the input."), .priv_size = sizeof(DnnDetectContext), .init = dnn_detect_init, .uninit = dnn_detect_uninit, - FILTER_INPUTS(ff_video_default_filterpad), + FILTER_INPUTS(dnn_detect_inputs), FILTER_OUTPUTS(ff_video_default_filterpad), FILTER_PIXFMTS_ARRAY(pix_fmts), .priv_class = &dnn_detect_class, -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-12-04 5:36 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-12-04 5:36 [FFmpeg-devel] [PATCH 1/4] libavfiter/dnn/dnn_backend_openvino: add multiple output support wenbin.chen-at-intel.com 2023-12-04 5:36 ` wenbin.chen-at-intel.com [this message] 2023-12-04 5:36 ` [FFmpeg-devel] [PATCH 3/4] libavfilter/vf_dnn_detect: Add yolov3 support wenbin.chen-at-intel.com 2023-12-04 5:36 ` [FFmpeg-devel] [PATCH 4/4] libavfilter/vf_dnn_detect: Add yolov4 support wenbin.chen-at-intel.com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20231204053633.1743228-2-wenbin.chen@intel.com \ --to=wenbin.chen-at-intel.com@ffmpeg.org \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git