From patchwork Thu May 6 08:46:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Ting" X-Patchwork-Id: 27611 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6109:0:0:0:0:0 with SMTP id v9csp1098469iob; Thu, 6 May 2021 01:56:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwviAFpkaelHFsTlzVy2U+jnOt/BJG2gHtbnPq4Bt841F3amKo6MNM+2H4xJ7iKoyLRZRK X-Received: by 2002:a17:906:4d02:: with SMTP id r2mr3231042eju.464.1620291392720; Thu, 06 May 2021 01:56:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620291392; cv=none; d=google.com; s=arc-20160816; b=gg6aqVGxJKgyYZLcoMo4amwudMHe0FYChigHMACqelRXyU9P/z5yd808Z6HC53Iplf 7cVPTdUm5VkkaXSHnxZuy6jHOgzgZigqxxe9gXufihQ5Kh6MyI+Uonv80SNNNMeGCbes h/WCwAdFpChgGiU9W3TCwg2LuxyclDyhIJhJSHVPkfp3n3ahRpo5ZJ71XghgxgXvGXZ8 yXSROn+NC7omvZ/SBU2inFNGIf2MJ5p3C/fXGBCprWgXb+IjvxBpKDgS9dzVy2kFsjEV qcygyVXKbAvNKJCt+MW2imT+8kyJ7ncPGmPClRmClYI4PU1DXgYy39cwFlFE0QRngUFv QBGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:ironport-sdr:ironport-sdr:delivered-to; bh=/TeRKr6GnUKyPGfQLBVXLstWDYaYxnHpMEmdCCiquEQ=; b=iKmPndqbIwOnbSH9SPBNP1VljKzBXoXxfCIiFYWaXS+1YMN1K3ioak93+gNamDQD55 Rw0BVu1nRFcnwiEyPS5PY3Yzp29pnu23X2sH/FaFm9LOtfVBfH4Efm10HmBYPmcBVuW2 MD4Ht99COCMC7PApK4F60yBH7ueFy7IWKc5+TEDLklNH+3cSVNX44a87bnvU4N7a21VT pWTvkvbpdFUOyWwo3qCiI+6uUBYUTBpkViwb/IpDGNPFVLYA7i0gwLh4+1B5plL668Oe pdfTm2sKFOKYuUGL8IhCmVN0aJGGidnU/IEjHIxHj1Nf7fqKVllt9VeRqx5nvuUD/kGd UIKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q19si1742838ejd.250.2021.05.06.01.56.32; Thu, 06 May 2021 01:56:32 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7CA3A6808A7; Thu, 6 May 2021 11:56:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AF81768074A for ; Thu, 6 May 2021 11:56:06 +0300 (EEST) IronPort-SDR: NZJAe4tvaSR9vp7u0f2+0Axxz0rdknO8xaLc7TFDPetu8oes+eh/a36UZXQOXL3n7xK83TEu3m MTY21UJGgz5Q== X-IronPort-AV: E=McAfee;i="6200,9189,9975"; a="177977595" X-IronPort-AV: E=Sophos;i="5.82,277,1613462400"; d="scan'208";a="177977595" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2021 01:55:54 -0700 IronPort-SDR: /HJ3BlMdtCczWBvKxISdzzgcKlzY4Q6wCz3c9aoi471AXLfTC3cmwuRY9h0JkgDAbg0j9VAghq Uq9vTNFGcdmw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,277,1613462400"; d="scan'208";a="607740308" Received: from semmer-ubuntu.sh.intel.com ([10.239.159.83]) by orsmga005.jf.intel.com with ESMTP; 06 May 2021 01:55:53 -0700 From: Ting Fu To: ffmpeg-devel@ffmpeg.org Date: Thu, 6 May 2021 16:46:09 +0800 Message-Id: <20210506084610.23487-3-ting.fu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210506084610.23487-1-ting.fu@intel.com> References: <20210506084610.23487-1-ting.fu@intel.com> Subject: [FFmpeg-devel] [PATCH V2 3/4] lavfi/dnn_backend_tensorflow: support detect model 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 0ouQnccBRgQc Signed-off-by: Ting Fu --- libavfilter/dnn/dnn_backend_tf.c | 39 ++++++++++++++++++++++++++------ libavfilter/vf_dnn_detect.c | 32 +++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_tf.c b/libavfilter/dnn/dnn_backend_tf.c index b6b1812cd9..622b5a8464 100644 --- a/libavfilter/dnn/dnn_backend_tf.c +++ b/libavfilter/dnn/dnn_backend_tf.c @@ -793,15 +793,40 @@ static DNNReturnType execute_model_tf(const DNNModel *model, const char *input_n outputs[i].data = TF_TensorData(output_tensors[i]); outputs[i].dt = TF_TensorType(output_tensors[i]); } - if (do_ioproc) { - if (tf_model->model->frame_post_proc != NULL) { - tf_model->model->frame_post_proc(out_frame, outputs, tf_model->model->filter_ctx); + switch (model->func_type) { + case DFT_PROCESS_FRAME: + //it only support 1 output if it's frame in & frame out + if (do_ioproc) { + if (tf_model->model->frame_post_proc != NULL) { + tf_model->model->frame_post_proc(out_frame, outputs, tf_model->model->filter_ctx); + } else { + ff_proc_from_dnn_to_frame(out_frame, outputs, ctx); + } } else { - ff_proc_from_dnn_to_frame(out_frame, outputs, ctx); + out_frame->width = outputs[0].width; + out_frame->height = outputs[0].height; + } + break; + case DFT_ANALYTICS_DETECT: + if (!model->detect_post_proc) { + av_log(ctx, AV_LOG_ERROR, "Detect filter needs provide post proc\n"); + return DNN_ERROR; + } + model->detect_post_proc(out_frame, outputs, nb_output, model->filter_ctx); + break; + default: + for (uint32_t i = 0; i < nb_output; ++i) { + if (output_tensors[i]) { + TF_DeleteTensor(output_tensors[i]); + } } - } else { - out_frame->width = outputs[0].width; - out_frame->height = outputs[0].height; + TF_DeleteTensor(input_tensor); + av_freep(&output_tensors); + av_freep(&tf_outputs); + av_freep(&outputs); + + av_log(ctx, AV_LOG_ERROR, "Tensorflow backend does not support this kind of dnn filter now\n"); + return DNN_ERROR; } for (uint32_t i = 0; i < nb_output; ++i) { diff --git a/libavfilter/vf_dnn_detect.c b/libavfilter/vf_dnn_detect.c index 1dbe4f29a4..7d39acb653 100644 --- a/libavfilter/vf_dnn_detect.c +++ b/libavfilter/vf_dnn_detect.c @@ -203,10 +203,40 @@ static int read_detect_label_file(AVFilterContext *context) return 0; } +static int check_output_nb(DnnDetectContext *ctx, DNNBackendType backend_type, int output_nb) +{ + switch(backend_type) { + case DNN_TF: + if (output_nb != 4) { + av_log(ctx, AV_LOG_ERROR, "Only support tensorflow detect model with 4 outputs, \ + but get %d instead\n", output_nb); + return AVERROR(EINVAL); + } + return 0; + case DNN_OV: + if (output_nb != 1) { + av_log(ctx, AV_LOG_ERROR, "Dnn detect filter with openvino backend needs 1 output only, \ + but get %d instead\n", output_nb); + return AVERROR(EINVAL); + } + return 0; + default: + avpriv_report_missing_feature(ctx, "Dnn detect filter does not support current backend\n"); + return AVERROR(EINVAL); + } + return 0; +} + static av_cold int dnn_detect_init(AVFilterContext *context) { DnnDetectContext *ctx = context->priv; - int ret = ff_dnn_init(&ctx->dnnctx, DFT_ANALYTICS_DETECT, context); + DnnContext *dnn_ctx = &ctx->dnnctx; + int ret; + + ret = ff_dnn_init(&ctx->dnnctx, DFT_ANALYTICS_DETECT, context); + if (ret < 0) + return ret; + ret = check_output_nb(ctx, dnn_ctx->backend_type, dnn_ctx->nb_outputs); if (ret < 0) return ret; ff_dnn_set_detect_post_proc(&ctx->dnnctx, dnn_detect_post_proc);