From 9e67850fd4f8c0137747415650d08925bc5a7460 Mon Sep 17 00:00:00 2001 From: yangruoqi713 Date: Mon, 10 Aug 2020 16:34:27 +0800 Subject: [PATCH] [MS][LITE] fix bug of arm cpu fp32 conv_depthwise: only support group equals output channel --- mindspore/lite/src/ops/convolution_depthwise.cc | 5 +++++ mindspore/lite/src/ops/deconvolution_depthwise.cc | 5 +++++ .../lite/src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.cc | 2 +- .../tools/converter/parser/caffe/caffe_convolution_parser.cc | 2 +- .../converter/parser/caffe/caffe_deconvolution_parser.cc | 2 +- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mindspore/lite/src/ops/convolution_depthwise.cc b/mindspore/lite/src/ops/convolution_depthwise.cc index c26bda7b6f2..2b8c11ba396 100644 --- a/mindspore/lite/src/ops/convolution_depthwise.cc +++ b/mindspore/lite/src/ops/convolution_depthwise.cc @@ -40,6 +40,7 @@ int DepthwiseConv2D::InferShape(std::vector inputs_, std::vect auto in_shape = input->shape(); int input_h = in_shape.at(1); int input_w = in_shape.at(2); + int input_channel = in_shape.at(3); int output_w = 0, output_h = 0; auto conv_prim = this->primitive->value_as_DepthwiseConv2D(); @@ -69,6 +70,10 @@ int DepthwiseConv2D::InferShape(std::vector inputs_, std::vect std::vector out_shape{input->shape()}; out_shape.at(1) = output_h; out_shape.at(2) = output_w; + if (conv_prim->channelMultiplier() * input_channel != weight->shape()[0]) { + MS_LOG(ERROR) << "Conv depthwise only support group equals output channel."; + return RET_ERROR; + } out_shape.at(3) = weight->shape()[0] * weight->shape()[3]; // in_channel * out_channel output->set_shape(out_shape); diff --git a/mindspore/lite/src/ops/deconvolution_depthwise.cc b/mindspore/lite/src/ops/deconvolution_depthwise.cc index 01e25424824..fe99cb4afd6 100644 --- a/mindspore/lite/src/ops/deconvolution_depthwise.cc +++ b/mindspore/lite/src/ops/deconvolution_depthwise.cc @@ -40,6 +40,7 @@ int DeconvDepthwiseConv2D::InferShape(std::vector inputs_, std auto in_shape = input->shape(); int input_h = in_shape.at(1); int input_w = in_shape.at(2); + int input_channel = in_shape.at(3); int output_w = 0, output_h = 0; auto conv_prim = this->primitive->value_as_DeDepthwiseConv2D(); @@ -58,6 +59,10 @@ int DeconvDepthwiseConv2D::InferShape(std::vector inputs_, std std::vector out_shape{input->shape()}; out_shape.at(1) = output_h; out_shape.at(2) = output_w; + if (conv_prim->channelMultiplier() * input_channel != weight->shape()[0]) { + MS_LOG(ERROR) << "Conv depthwise only support group equals output channel."; + return RET_ERROR; + } out_shape.at(3) = weight->shape()[0] * weight->shape()[3]; // in_channel * out_channel output->set_shape(out_shape); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.cc index 0b8123c2e10..1994dc30cb2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.cc @@ -53,7 +53,7 @@ void InitSlidingParam(SlidingWindowParam *sliding, const ConvParameter *conv_par sliding->in_step_ = conv_param->input_h_ * conv_param->input_w_ * sliding->block_channel_; // for batch loop sliding->in_h_step_ = conv_param->input_w_ * sliding->block_channel_; sliding->in_sh_step_ = conv_param->input_w_ * sliding->block_channel_ * conv_param->stride_h_; // stride H - sliding->in_sw_step_ = sliding->block_channel_ * conv_param->stride_h_; // stride W + sliding->in_sw_step_ = sliding->block_channel_ * conv_param->stride_w_; // stride W sliding->in_kh_step_ = conv_param->input_w_ * sliding->block_channel_ * conv_param->dilation_h_; // kernel H sliding->in_kw_step_ = sliding->block_channel_ * conv_param->dilation_w_; // kernel W sliding->kernel_step_ = conv_param->kernel_w_ * conv_param->kernel_h_ * block; diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_convolution_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_convolution_parser.cc index 5c622f13d0d..17b657143ef 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_convolution_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_convolution_parser.cc @@ -20,7 +20,7 @@ namespace mindspore { namespace lite { void CaffeConvolutionParser::ParseGroupConvolution(schema::CNodeT *op, schema::Conv2DT *attr) { - if (attr == nullptr || attr->group == 1 || attr->group != attr->channelOut) { + if (attr == nullptr || attr->group == 1) { return; } std::unique_ptr depthwiseConv2DParam(new schema::DepthwiseConv2DT()); diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_deconvolution_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_deconvolution_parser.cc index be9682f2fd9..75401ea4b48 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_deconvolution_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_deconvolution_parser.cc @@ -20,7 +20,7 @@ namespace mindspore { namespace lite { void CaffeDeconvolutionParser::ParseGroupDeconvolution(schema::CNodeT *op, schema::DeConv2DT *attr) { - if (attr == nullptr || attr->group == 1 || attr->group != attr->channelIn) { + if (attr == nullptr || attr->group == 1) { return; }