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 E7295471A8 for ; Wed, 27 Dec 2023 04:17:26 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0798368CBF3; Wed, 27 Dec 2023 06:17:24 +0200 (EET) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D7D2968CB75 for ; Wed, 27 Dec 2023 06:17:16 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703650643; x=1735186643; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=YekNQE4vUqFQktnfM5QzSGmMXqjPGHirrwZIQV92gQw=; b=a1clnx5+Fl4pauz+CqmUwUA6yb8Fa9/PrZ+jQtZyEReKLhDXMKIX+8IL Yl/DuaCk/bR8qoM/pqhtxsenAd5nZqqpZpINQH6wFl1yh2vAgBK3ereV/ lS1R2EL0Gh0Xr1LkcndTjyPvR0D7huzTMcVwt3rASYBiTMSNo9J7OCeJb t+5Srl1t78jkt/9nipnA924hTfs3xlZX9LS3OreMLW5O00dQbfdaPaKIV gahAUCyuIuXK5Z9L2Qb9JxNz6KL5wFmSqD8KMXrtN3ePA53XYcoiDh1kL N2XJIoNb1kMbcF5XESOkM6Xie5Y2GP/kMuieM5FHRBlZqnKgCHEmAxY51 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10935"; a="15082288" X-IronPort-AV: E=Sophos;i="6.04,308,1695711600"; d="scan'208";a="15082288" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Dec 2023 20:17:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10935"; a="848581532" X-IronPort-AV: E=Sophos;i="6.04,308,1695711600"; d="scan'208";a="848581532" Received: from wenbin-z390-aorus-ultra.sh.intel.com ([10.239.156.43]) by fmsmga004.fm.intel.com with ESMTP; 26 Dec 2023 20:16:59 -0800 From: wenbin.chen-at-intel.com@ffmpeg.org To: ffmpeg-devel@ffmpeg.org Date: Wed, 27 Dec 2023 12:16:57 +0800 Message-Id: <20231227041658.392174-1-wenbin.chen@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] libavfilter/dnn_backend_openvino: Add dynamic output support 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 Add dynamic outputs support. Some models don't have fixed output size. Its size changes according to result. Now openvino can run these kinds of models. Signed-off-by: Wenbin Chen --- libavfilter/dnn/dnn_backend_openvino.c | 134 +++++++++++-------------- 1 file changed, 59 insertions(+), 75 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c index 671a995c70..e207d44584 100644 --- a/libavfilter/dnn/dnn_backend_openvino.c +++ b/libavfilter/dnn/dnn_backend_openvino.c @@ -219,31 +219,26 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) task = lltask->task; #if HAVE_OPENVINO2 - if (!ov_model_is_dynamic(ov_model->ov_model)) { - if (ov_model->input_port) { - ov_output_const_port_free(ov_model->input_port); - ov_model->input_port = NULL; - } - status = ov_model_const_input_by_name(ov_model->ov_model, task->input_name, &ov_model->input_port); - if (status != OK) { - av_log(ctx, AV_LOG_ERROR, "Failed to get input port shape.\n"); - return ov2_map_error(status, NULL); - } - status = ov_const_port_get_shape(ov_model->input_port, &input_shape); - if (status != OK) { - av_log(ctx, AV_LOG_ERROR, "Failed to get input port shape.\n"); - return ov2_map_error(status, NULL); - } - dims = input_shape.dims; - status = ov_port_get_element_type(ov_model->input_port, &precision); - if (status != OK) { - av_log(ctx, AV_LOG_ERROR, "Failed to get input port data type.\n"); - ov_shape_free(&input_shape); - return ov2_map_error(status, NULL); - } - } else { - avpriv_report_missing_feature(ctx, "Do not support dynamic model."); - return AVERROR(ENOSYS); + if (ov_model->input_port) { + ov_output_const_port_free(ov_model->input_port); + ov_model->input_port = NULL; + } + status = ov_model_const_input_by_name(ov_model->ov_model, task->input_name, &ov_model->input_port); + if (status != OK) { + av_log(ctx, AV_LOG_ERROR, "Failed to get input port shape.\n"); + return ov2_map_error(status, NULL); + } + status = ov_const_port_get_shape(ov_model->input_port, &input_shape); + if (status != OK) { + av_log(ctx, AV_LOG_ERROR, "Failed to get input port shape.\n"); + return ov2_map_error(status, NULL); + } + dims = input_shape.dims; + status = ov_port_get_element_type(ov_model->input_port, &precision); + if (status != OK) { + av_log(ctx, AV_LOG_ERROR, "Failed to get input port data type.\n"); + ov_shape_free(&input_shape); + return ov2_map_error(status, NULL); } input.height = dims[1]; input.width = dims[2]; @@ -1049,30 +1044,22 @@ static int get_input_ov(void *model, DNNData *input, const char *input_name) ov_element_type_e precision; int64_t* dims; ov_status_e status; - if (!ov_model_is_dynamic(ov_model->ov_model)) { - status = ov_model_const_input_by_name(ov_model->ov_model, input_name, &ov_model->input_port); - if (status != OK) { - av_log(ctx, AV_LOG_ERROR, "Failed to get input port shape.\n"); - return ov2_map_error(status, NULL); - } - - status = ov_const_port_get_shape(ov_model->input_port, &input_shape); - if (status != OK) { - av_log(ctx, AV_LOG_ERROR, "Failed to get input port shape.\n"); - return ov2_map_error(status, NULL); - } - dims = input_shape.dims; - - status = ov_port_get_element_type(ov_model->input_port, &precision); - if (status != OK) { - av_log(ctx, AV_LOG_ERROR, "Failed to get input port data type.\n"); - return ov2_map_error(status, NULL); - } - } else { - avpriv_report_missing_feature(ctx, "Do not support dynamic model now."); - return AVERROR(ENOSYS); + status = ov_model_const_input_by_name(ov_model->ov_model, input_name, &ov_model->input_port); + if (status != OK) { + av_log(ctx, AV_LOG_ERROR, "Failed to get input port shape.\n"); + return ov2_map_error(status, NULL); } - + status = ov_port_get_element_type(ov_model->input_port, &precision); + if (status != OK) { + av_log(ctx, AV_LOG_ERROR, "Failed to get input port data type.\n"); + return ov2_map_error(status, NULL); + } + status = ov_const_port_get_shape(ov_model->input_port, &input_shape); + if (status != OK) { + av_log(ctx, AV_LOG_ERROR, "Failed to get input port shape.\n"); + return ov2_map_error(status, NULL); + } + dims = input_shape.dims; if (dims[1] <= 3) { // NCHW input->channels = dims[1]; input->height = input_resizable ? -1 : dims[2]; @@ -1083,7 +1070,7 @@ static int get_input_ov(void *model, DNNData *input, const char *input_name) input->channels = dims[3]; } input->dt = precision_to_datatype(precision); - + ov_shape_free(&input_shape); return 0; #else char *model_input_name = NULL; @@ -1267,34 +1254,31 @@ static int get_output_ov(void *model, const char *input_name, int input_width, i #if HAVE_OPENVINO2 if (ctx->options.input_resizable) { - if (!ov_model_is_dynamic(ov_model->ov_model)) { - status = ov_partial_shape_create(4, dims, &partial_shape); - if (status != OK) { - av_log(ctx, AV_LOG_ERROR, "Failed create partial shape.\n"); - return ov2_map_error(status, NULL); - } - status = ov_const_port_get_shape(ov_model->input_port, &input_shape); - input_shape.dims[2] = input_height; - input_shape.dims[3] = input_width; - if (status != OK) { - av_log(ctx, AV_LOG_ERROR, "Failed create shape for model input resize.\n"); - return ov2_map_error(status, NULL); - } + status = ov_partial_shape_create(4, dims, &partial_shape); + if (status != OK) { + av_log(ctx, AV_LOG_ERROR, "Failed to create partial shape.\n"); + return ov2_map_error(status, NULL); + } + status = ov_const_port_get_shape(ov_model->input_port, &input_shape); + if (status != OK) { + av_log(ctx, AV_LOG_ERROR, "Failed to create shape for model input resize.\n"); + return ov2_map_error(status, NULL); + } + input_shape.dims[2] = input_height; + input_shape.dims[3] = input_width; - status = ov_shape_to_partial_shape(input_shape, &partial_shape); - if (status != OK) { - av_log(ctx, AV_LOG_ERROR, "Failed create partial shape for model input resize.\n"); - return ov2_map_error(status, NULL); - } + status = ov_shape_to_partial_shape(input_shape, &partial_shape); + ov_shape_free(&input_shape); + if (status != OK) { + av_log(ctx, AV_LOG_ERROR, "Failed to create partial shape for model input resize.\n"); + return ov2_map_error(status, NULL); + } - status = ov_model_reshape_single_input(ov_model->ov_model, partial_shape); - if (status != OK) { - av_log(ctx, AV_LOG_ERROR, "Failed to reszie model input.\n"); - return ov2_map_error(status, NULL); - } - } else { - avpriv_report_missing_feature(ctx, "Do not support dynamic model."); - return AVERROR(ENOTSUP); + status = ov_model_reshape_single_input(ov_model->ov_model, partial_shape); + ov_partial_shape_free(&partial_shape); + if (status != OK) { + av_log(ctx, AV_LOG_ERROR, "Failed to reszie model input.\n"); + return ov2_map_error(status, NULL); } } -- 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".