From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 8E966482A7 for ; Tue, 21 Nov 2023 02:20:33 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5BE3968CBC7; Tue, 21 Nov 2023 04:20:30 +0200 (EET) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CF22168C8C8 for ; Tue, 21 Nov 2023 04:20:22 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700533228; x=1732069228; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=oclU/1rotUckeavEb8ig6pzoF5igc2VRdkbezGrOy5I=; b=aPw1bu8bM5FLNQUBeiX6wx0+J0Ld/Wosf3jIesJlvf2mNZBCBi/GLCWB jHcYSVdbV8Bxq8yUcPlJCCeR2ElbI0CzNqo96QsExLsMT7uqews7wcWXL gukN10vDeK4s05SUao48tQbjT0CZDLEwJuFi8vbAPzKUV21aCcIFpsgYb vWkGS/Iy4Numf3I4P+g6KuKSe6yLpTikls71z9vZwJ1H//pMMLZSMZdH3 Zu6YDDTsLTh9udMAbzm7PHMWdJWiX907peyk597zyl/PzDS2rRK2uwE3x 7DtrheWDY31lRZszSGQLpupyLeSlxzl+7G+p4ylxh4T6HIE+4keIOeR63 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="371920348" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="371920348" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 18:20:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="7749793" Received: from wenbin-z390-aorus-ultra.sh.intel.com ([10.239.156.43]) by orviesa002.jf.intel.com with ESMTP; 20 Nov 2023 18:20:19 -0800 From: wenbin.chen-at-intel.com@ffmpeg.org To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Nov 2023 10:20:17 +0800 Message-Id: <20231121022018.285533-1-wenbin.chen@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] libavfilter/vf_dnn_detect: Add model_type option. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Wenbin Chen There are many kinds of detection DNN model and they have different preprocess and postprocess methods. To support more models, "model_type" option is added to help to choose preprocess and postprocess function. Signed-off-by: Wenbin Chen --- libavfilter/vf_dnn_detect.c | 42 ++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/libavfilter/vf_dnn_detect.c b/libavfilter/vf_dnn_detect.c index b5dae42c65..9db90ee4cf 100644 --- a/libavfilter/vf_dnn_detect.c +++ b/libavfilter/vf_dnn_detect.c @@ -31,6 +31,10 @@ #include "libavutil/avstring.h" #include "libavutil/detection_bbox.h" +typedef enum { + DDMT_SSD +} DNNDetectionModelType; + typedef struct DnnDetectContext { const AVClass *class; DnnContext dnnctx; @@ -38,6 +42,7 @@ typedef struct DnnDetectContext { char *labels_filename; char **labels; int label_count; + DNNDetectionModelType model_type; } DnnDetectContext; #define OFFSET(x) offsetof(DnnDetectContext, dnnctx.x) @@ -54,12 +59,14 @@ static const AVOption dnn_detect_options[] = { DNN_COMMON_OPTIONS { "confidence", "threshold of confidence", OFFSET2(confidence), AV_OPT_TYPE_FLOAT, { .dbl = 0.5 }, 0, 1, FLAGS}, { "labels", "path to labels file", OFFSET2(labels_filename), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS }, + { "model_type", "DNN detection model type", OFFSET2(model_type), AV_OPT_TYPE_INT, { .i64 = DDMT_SSD }, INT_MIN, INT_MAX, FLAGS, "model_type" }, + { "ssd", "output shape [1, 1, N, 7]", 0, AV_OPT_TYPE_CONST, { .i64 = DDMT_SSD }, 0, 0, FLAGS, "model_type" }, { NULL } }; AVFILTER_DEFINE_CLASS(dnn_detect); -static int dnn_detect_post_proc_ov(AVFrame *frame, DNNData *output, AVFilterContext *filter_ctx) +static int dnn_detect_post_proc_ssd(AVFrame *frame, DNNData *output, AVFilterContext *filter_ctx) { DnnDetectContext *ctx = filter_ctx->priv; float conf_threshold = ctx->confidence; @@ -67,14 +74,12 @@ static int dnn_detect_post_proc_ov(AVFrame *frame, DNNData *output, AVFilterCont int detect_size = output->width; float *detections = output->data; int nb_bboxes = 0; - AVFrameSideData *sd; - AVDetectionBBox *bbox; AVDetectionBBoxHeader *header; + AVDetectionBBox *bbox; - sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DETECTION_BBOXES); - if (sd) { - av_log(filter_ctx, AV_LOG_ERROR, "already have bounding boxes in side data.\n"); - return -1; + if (output->width != 7) { + av_log(filter_ctx, AV_LOG_ERROR, "Model output shape doesn't match ssd requirement.\n"); + return AVERROR(EINVAL); } for (int i = 0; i < proposal_count; ++i) { @@ -135,6 +140,29 @@ static int dnn_detect_post_proc_ov(AVFrame *frame, DNNData *output, AVFilterCont return 0; } +static int dnn_detect_post_proc_ov(AVFrame *frame, DNNData *output, AVFilterContext *filter_ctx) +{ + AVFrameSideData *sd; + DnnDetectContext *ctx = filter_ctx->priv; + int ret = 0; + + sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DETECTION_BBOXES); + if (sd) { + av_log(filter_ctx, AV_LOG_ERROR, "already have bounding boxes in side data.\n"); + return -1; + } + + switch (ctx->model_type) { + case DDMT_SSD: + ret = dnn_detect_post_proc_ssd(frame, output, filter_ctx); + if (ret < 0) + return ret; + break; + } + + return 0; +} + static int dnn_detect_post_proc_tf(AVFrame *frame, DNNData *output, AVFilterContext *filter_ctx) { DnnDetectContext *ctx = filter_ctx->priv; -- 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".