From patchwork Wed Oct 9 14:08:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guo, Yejun" X-Patchwork-Id: 15633 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 5095A44A2E1 for ; Wed, 9 Oct 2019 17:13:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 29EF66880E8; Wed, 9 Oct 2019 17:13:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A2715687FB2 for ; Wed, 9 Oct 2019 17:13:37 +0300 (EEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Oct 2019 07:13:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,276,1566889200"; d="scan'208";a="200137976" Received: from yguo18-skl-u1604.sh.intel.com ([10.239.13.25]) by FMSMGA003.fm.intel.com with ESMTP; 09 Oct 2019 07:13:34 -0700 From: "Guo, Yejun" To: ffmpeg-devel@ffmpeg.org Date: Wed, 9 Oct 2019 22:08:04 +0800 Message-Id: <1570630084-20413-1-git-send-email-yejun.guo@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH V3 1/3] avfilter/dnn: add DLT prefix for enum DNNLayerType to avoid potential conflicts X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: yejun.guo@intel.com MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" and also change CONV to DLT_CONV2D for better description Signed-off-by: Guo, Yejun --- libavfilter/dnn/dnn_backend_native.c | 25 +++++++++++-------------- libavfilter/dnn/dnn_backend_native.h | 12 +++++++++++- libavfilter/dnn/dnn_backend_tf.c | 10 +++++----- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_native.c b/libavfilter/dnn/dnn_backend_native.c index 68fca50..97549d3 100644 --- a/libavfilter/dnn/dnn_backend_native.c +++ b/libavfilter/dnn/dnn_backend_native.c @@ -188,8 +188,9 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename) for (layer = 0; layer < network->layers_num; ++layer){ layer_type = (int32_t)avio_rl32(model_file_context); dnn_size += 4; + network->layers[layer].type = layer_type; switch (layer_type){ - case CONV: + case DLT_CONV2D: conv_params = av_malloc(sizeof(ConvolutionalParams)); if (!conv_params){ avio_closep(&model_file_context); @@ -231,10 +232,9 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename) network->layers[layer].input_operand_indexes[0] = (int32_t)avio_rl32(model_file_context); network->layers[layer].output_operand_index = (int32_t)avio_rl32(model_file_context); dnn_size += 8; - network->layers[layer].type = CONV; network->layers[layer].params = conv_params; break; - case DEPTH_TO_SPACE: + case DLT_DEPTH_TO_SPACE: depth_to_space_params = av_malloc(sizeof(DepthToSpaceParams)); if (!depth_to_space_params){ avio_closep(&model_file_context); @@ -246,10 +246,9 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename) network->layers[layer].input_operand_indexes[0] = (int32_t)avio_rl32(model_file_context); network->layers[layer].output_operand_index = (int32_t)avio_rl32(model_file_context); dnn_size += 8; - network->layers[layer].type = DEPTH_TO_SPACE; network->layers[layer].params = depth_to_space_params; break; - case MIRROR_PAD: + case DLT_MIRROR_PAD: pad_params = av_malloc(sizeof(LayerPadParams)); if (!pad_params){ avio_closep(&model_file_context); @@ -266,10 +265,9 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename) network->layers[layer].input_operand_indexes[0] = (int32_t)avio_rl32(model_file_context); network->layers[layer].output_operand_index = (int32_t)avio_rl32(model_file_context); dnn_size += 8; - network->layers[layer].type = MIRROR_PAD; network->layers[layer].params = pad_params; break; - case MAXIMUM: + case DLT_MAXIMUM: maximum_params = av_malloc(sizeof(*maximum_params)); if (!maximum_params){ avio_closep(&model_file_context); @@ -278,7 +276,6 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename) } maximum_params->val.u32 = avio_rl32(model_file_context); dnn_size += 4; - network->layers[layer].type = MAXIMUM; network->layers[layer].params = maximum_params; network->layers[layer].input_operand_indexes[0] = (int32_t)avio_rl32(model_file_context); network->layers[layer].output_operand_index = (int32_t)avio_rl32(model_file_context); @@ -347,27 +344,27 @@ DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *output for (layer = 0; layer < network->layers_num; ++layer){ switch (network->layers[layer].type){ - case CONV: + case DLT_CONV2D: conv_params = (ConvolutionalParams *)network->layers[layer].params; convolve(network->operands, network->layers[layer].input_operand_indexes, network->layers[layer].output_operand_index, conv_params); break; - case DEPTH_TO_SPACE: + case DLT_DEPTH_TO_SPACE: depth_to_space_params = (DepthToSpaceParams *)network->layers[layer].params; depth_to_space(network->operands, network->layers[layer].input_operand_indexes, network->layers[layer].output_operand_index, depth_to_space_params->block_size); break; - case MIRROR_PAD: + case DLT_MIRROR_PAD: pad_params = (LayerPadParams *)network->layers[layer].params; dnn_execute_layer_pad(network->operands, network->layers[layer].input_operand_indexes, network->layers[layer].output_operand_index, pad_params); break; - case MAXIMUM: + case DLT_MAXIMUM: maximum_params = (DnnLayerMaximumParams *)network->layers[layer].params; dnn_execute_layer_maximum(network->operands, network->layers[layer].input_operand_indexes, network->layers[layer].output_operand_index, maximum_params); break; - case INPUT: + case DLT_INPUT: return DNN_ERROR; } } @@ -408,7 +405,7 @@ void ff_dnn_free_model_native(DNNModel **model) { network = (ConvolutionalNetwork *)(*model)->model; for (layer = 0; layer < network->layers_num; ++layer){ - if (network->layers[layer].type == CONV){ + if (network->layers[layer].type == DLT_CONV2D){ conv_params = (ConvolutionalParams *)network->layers[layer].params; av_freep(&conv_params->kernel); av_freep(&conv_params->biases); diff --git a/libavfilter/dnn/dnn_backend_native.h b/libavfilter/dnn/dnn_backend_native.h index 3f2840c..761e5ed 100644 --- a/libavfilter/dnn/dnn_backend_native.h +++ b/libavfilter/dnn/dnn_backend_native.h @@ -30,7 +30,17 @@ #include "../dnn_interface.h" #include "libavformat/avio.h" -typedef enum {INPUT = 0, CONV = 1, DEPTH_TO_SPACE = 2, MIRROR_PAD = 3, MAXIMUM = 4} DNNLayerType; +/** + * the enum value of DNNLayerType should not be changed, + * the same values are used in convert_from_tensorflow.py + */ +typedef enum { + DLT_INPUT = 0, + DLT_CONV2D = 1, + DLT_DEPTH_TO_SPACE = 2, + DLT_MIRROR_PAD = 3, + DLT_MAXIMUM = 4 +} DNNLayerType; typedef enum {DOT_INPUT = 1, DOT_OUTPUT = 2, DOT_INTERMEDIATE = DOT_INPUT | DOT_INPUT} DNNOperandType; diff --git a/libavfilter/dnn/dnn_backend_tf.c b/libavfilter/dnn/dnn_backend_tf.c index 612d2e0..c8dff51 100644 --- a/libavfilter/dnn/dnn_backend_tf.c +++ b/libavfilter/dnn/dnn_backend_tf.c @@ -499,22 +499,22 @@ static DNNReturnType load_native_model(TFModel *tf_model, const char *model_file for (layer = 0; layer < conv_network->layers_num; ++layer){ switch (conv_network->layers[layer].type){ - case INPUT: + case DLT_INPUT: layer_add_res = DNN_SUCCESS; break; - case CONV: + case DLT_CONV2D: layer_add_res = add_conv_layer(tf_model, transpose_op, &op, (ConvolutionalParams *)conv_network->layers[layer].params, layer); break; - case DEPTH_TO_SPACE: + case DLT_DEPTH_TO_SPACE: layer_add_res = add_depth_to_space_layer(tf_model, &op, (DepthToSpaceParams *)conv_network->layers[layer].params, layer); break; - case MIRROR_PAD: + case DLT_MIRROR_PAD: layer_add_res = add_pad_layer(tf_model, &op, (LayerPadParams *)conv_network->layers[layer].params, layer); break; - case MAXIMUM: + case DLT_MAXIMUM: layer_add_res = add_maximum_layer(tf_model, &op, (DnnLayerMaximumParams *)conv_network->layers[layer].params, layer); break;