From 0895bb438d6c9509632a9b3ff22dd7ead5e603cd Mon Sep 17 00:00:00 2001 From: daquexian Date: Wed, 6 Nov 2019 07:24:05 +0800 Subject: [PATCH] 'converter_simple' should not exist, all related logic should be implemented in Convert() --- include/tools/onnx2daq/OnnxConverter.h | 41 +++++++++++++------------- ops.yml | 5 +--- tools/onnx2daq/OnnxConverter.cpp | 28 +++++++++++------- tools/onnx2daq/OnnxConverterImpl.cpp | 18 ++++++----- 4 files changed, 48 insertions(+), 44 deletions(-) diff --git a/include/tools/onnx2daq/OnnxConverter.h b/include/tools/onnx2daq/OnnxConverter.h index 48a6d01..be7430b 100644 --- a/include/tools/onnx2daq/OnnxConverter.h +++ b/include/tools/onnx2daq/OnnxConverter.h @@ -110,26 +110,23 @@ class OnnxConverter { void SetIdentity(const std::string &input_name, const std::string &output_name); // OnnxConverter auto generated methods start - void AddLayerCONV_2DImpl(const std::string &input, - const std::string &weight, - const dnn::optional &bias, - int32_t padding_left, int32_t padding_right, - int32_t padding_top, int32_t padding_bottom, - int32_t stride_x, int32_t stride_y, - const std::string &output); - void AddLayerAVERAGE_POOL_2DImpl(const std::string &input, - int32_t padding_left, - int32_t padding_right, int32_t padding_top, - int32_t padding_bottom, int32_t stride_x, - int32_t stride_y, int32_t kernel_width, - int32_t kernel_height, - const std::string &output); - void AddLayerMAX_POOL_2DImpl(const std::string &input, int32_t padding_left, + void AddLayerCONV_2D(const std::string &input, const std::string &weight, + const dnn::optional &bias, + int32_t padding_left, int32_t padding_right, + int32_t padding_top, int32_t padding_bottom, + int32_t stride_x, int32_t stride_y, + const std::string &output); + void AddLayerAVERAGE_POOL_2D(const std::string &input, int32_t padding_left, int32_t padding_right, int32_t padding_top, int32_t padding_bottom, int32_t stride_x, int32_t stride_y, int32_t kernel_width, int32_t kernel_height, const std::string &output); + void AddLayerMAX_POOL_2D(const std::string &input, int32_t padding_left, + int32_t padding_right, int32_t padding_top, + int32_t padding_bottom, int32_t stride_x, + int32_t stride_y, int32_t kernel_width, + int32_t kernel_height, const std::string &output); void AddLayerRELU(const std::string &input, const std::string &output); void AddLayerSOFTMAX(const std::string &input, float beta, const std::string &output); @@ -141,12 +138,14 @@ class OnnxConverter { const std::string &output); void AddLayerCONCATENATION(const std::vector &inputs, int32_t axis, const std::string &output); - void AddLayerDEPTHWISE_CONV_2DImpl( - const std::string &input, const std::string &weight, - const dnn::optional &bias, int32_t padding_left, - int32_t padding_right, int32_t padding_top, int32_t padding_bottom, - int32_t stride_x, int32_t stride_y, int32_t depth_multiplier, - const std::string &output); + void AddLayerDEPTHWISE_CONV_2D(const std::string &input, + const std::string &weight, + const dnn::optional &bias, + int32_t padding_left, int32_t padding_right, + int32_t padding_top, int32_t padding_bottom, + int32_t stride_x, int32_t stride_y, + int32_t depth_multiplier, + const std::string &output); void AddLayerBATCH_TO_SPACE_ND(const std::string &input, const std::vector &block_sizes, const std::string &output); diff --git a/ops.yml b/ops.yml index 57e14a7..840cf39 100644 --- a/ops.yml +++ b/ops.yml @@ -46,7 +46,6 @@ needed_by_shaper: true fused: true support_quant_asymm: true - converter_simple: false api: 27 - input: @@ -93,7 +92,6 @@ nnapi: AVERAGE_POOL_2D shaper: Pool fused: true - converter_simple: false # builder_simple: false support_quant_asymm: true api: 27 @@ -143,7 +141,6 @@ nnapi: MAX_POOL_2D shaper: Pool fused: true - converter_simple: false # builder_simple: false support_quant_asymm: true api: 27 @@ -244,7 +241,7 @@ cpp_type: int32_t fused: true support_quant_asymm: true - converter_simple: false + # converter_simple: false api: 27 - input: diff --git a/tools/onnx2daq/OnnxConverter.cpp b/tools/onnx2daq/OnnxConverter.cpp index b20a689..84da2f8 100644 --- a/tools/onnx2daq/OnnxConverter.cpp +++ b/tools/onnx2daq/OnnxConverter.cpp @@ -717,13 +717,13 @@ void OnnxConverter::Convert(const ONNX_NAMESPACE::ModelProto &model_proto, const auto &onnx_weight = onnx_tensors_.at(ori_weight_name); if (group == 1) { VLOG(5) << "Vanilla conv"; - AddLayerCONV_2DImpl(input_name, ori_weight_name, bias_name, - onnx_pads[1], onnx_pads[3], onnx_pads[0], - onnx_pads[2], onnx_strides[1], - onnx_strides[0], output_name); + AddLayerCONV_2D(input_name, ori_weight_name, bias_name, + onnx_pads[1], onnx_pads[3], onnx_pads[0], + onnx_pads[2], onnx_strides[1], onnx_strides[0], + output_name); } else if (onnx_weight.shape[1] == 1) { // depthwise VLOG(5) << "Depthwise conv"; - AddLayerDEPTHWISE_CONV_2DImpl( + AddLayerDEPTHWISE_CONV_2D( input_name, ori_weight_name, bias_name, onnx_pads[1], onnx_pads[3], onnx_pads[0], onnx_pads[2], onnx_strides[1], onnx_strides[0], onnx_weight.shape[0] / group, output_name); @@ -737,8 +737,8 @@ void OnnxConverter::Convert(const ONNX_NAMESPACE::ModelProto &model_proto, VLOG(5) << "Start converting Pool"; const auto input_name = m(node.input(0)); const auto output_name = m(node.output(0)); - vector nnapi_strides, nnapi_pads, kernel_shape; if (op == "AveragePool" || op == "MaxPool") { + vector nnapi_strides, nnapi_pads, kernel_shape; kernel_shape = helper.get("kernel_shape", vector{0, 0}); const auto count_include_pad = helper.get("count_include_pad", 0); @@ -765,20 +765,26 @@ void OnnxConverter::Convert(const ONNX_NAMESPACE::ModelProto &model_proto, CHECK_EQ(kernel_shape.size(), 2ul); CHECK_EQ(nnapi_strides.size(), 2ul); if (op == "AveragePool") { - AddLayerAVERAGE_POOL_2DImpl( + AddLayerAVERAGE_POOL_2D( input_name, onnx_pads[1], onnx_pads[3], onnx_pads[0], onnx_pads[2], onnx_strides[1], onnx_strides[0], kernel_shape[1], kernel_shape[0], output_name); } else { - AddLayerMAX_POOL_2DImpl( + AddLayerMAX_POOL_2D( input_name, onnx_pads[1], onnx_pads[3], onnx_pads[0], onnx_pads[2], onnx_strides[1], onnx_strides[0], kernel_shape[1], kernel_shape[0], output_name); } } else { - // -1 means global - AddLayerAVERAGE_POOL_2DImpl(input_name, 0, 0, 0, 0, 1, 1, -1, - -1, output_name); + if (op == "GlobalAveragePool") { + AddLayerAVERAGE_POOL_2D( + input_name, 0, 0, 0, 0, 1, 1, shaper_[input_name][1], + shaper_[input_name][0], output_name); + } else { + AddLayerMAX_POOL_2D(input_name, 0, 0, 0, 0, 1, 1, + shaper_[input_name][1], + shaper_[input_name][0], output_name); + } } VLOG(5) << "Converting Pool completed"; } else if (op == "Relu") { diff --git a/tools/onnx2daq/OnnxConverterImpl.cpp b/tools/onnx2daq/OnnxConverterImpl.cpp index aedd7f4..3d714ad 100644 --- a/tools/onnx2daq/OnnxConverterImpl.cpp +++ b/tools/onnx2daq/OnnxConverterImpl.cpp @@ -106,11 +106,13 @@ namespace dnn { // } // OnnxConverter auto generated methods start -void OnnxConverter::AddLayerCONV_2DImpl( - const std::string &input, const std::string &weight, - const dnn::optional &bias, int32_t padding_left, - int32_t padding_right, int32_t padding_top, int32_t padding_bottom, - int32_t stride_x, int32_t stride_y, const std::string &output) { +void OnnxConverter::AddLayerCONV_2D(const std::string &input, + const std::string &weight, + const dnn::optional &bias, + int32_t padding_left, int32_t padding_right, + int32_t padding_top, int32_t padding_bottom, + int32_t stride_x, int32_t stride_y, + const std::string &output) { const auto activation = FindActivation(model_proto_, output); { @@ -161,7 +163,7 @@ void OnnxConverter::AddLayerCONV_2DImpl( layers_.push_back(layer); } -void OnnxConverter::AddLayerAVERAGE_POOL_2DImpl( +void OnnxConverter::AddLayerAVERAGE_POOL_2D( const std::string &input, int32_t padding_left, int32_t padding_right, int32_t padding_top, int32_t padding_bottom, int32_t stride_x, int32_t stride_y, int32_t kernel_width, int32_t kernel_height, @@ -192,7 +194,7 @@ void OnnxConverter::AddLayerAVERAGE_POOL_2DImpl( layers_.push_back(layer); } -void OnnxConverter::AddLayerMAX_POOL_2DImpl( +void OnnxConverter::AddLayerMAX_POOL_2D( const std::string &input, int32_t padding_left, int32_t padding_right, int32_t padding_top, int32_t padding_bottom, int32_t stride_x, int32_t stride_y, int32_t kernel_width, int32_t kernel_height, @@ -378,7 +380,7 @@ void OnnxConverter::AddLayerCONCATENATION( layers_.push_back(layer); } -void OnnxConverter::AddLayerDEPTHWISE_CONV_2DImpl( +void OnnxConverter::AddLayerDEPTHWISE_CONV_2D( const std::string &input, const std::string &weight, const dnn::optional &bias, int32_t padding_left, int32_t padding_right, int32_t padding_top, int32_t padding_bottom,