add DepthwiseConv multiplier support,fix group conv int8

pull/9780/head
gongdaguo 5 years ago
parent ea98943848
commit 36426425c5

@ -307,6 +307,12 @@ kernel::LiteKernel *CpuConvInt8KernelSelect(const std::vector<lite::Tensor *> &i
return kernel; return kernel;
} }
void CopyTensorQuantParam(lite::Tensor *dst, lite::Tensor *src) {
for (size_t i = 0; i < src->quant_params().size(); i++) {
dst->AddQuantParam(src->quant_params().at(i));
}
}
kernel::LiteKernel *CpuGroupConvInt8KernelCreator(const std::vector<lite::Tensor *> &inputs, kernel::LiteKernel *CpuGroupConvInt8KernelCreator(const std::vector<lite::Tensor *> &inputs,
const std::vector<lite::Tensor *> &outputs, OpParameter *op_parameter, const std::vector<lite::Tensor *> &outputs, OpParameter *op_parameter,
const InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive, const InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive,
@ -359,6 +365,7 @@ kernel::LiteKernel *CpuGroupConvInt8KernelCreator(const std::vector<lite::Tensor
MS_LOG(ERROR) << "create input tensor failed."; MS_LOG(ERROR) << "create input tensor failed.";
return nullptr; return nullptr;
} }
CopyTensorQuantParam(in_tensor, inputs[kInputIndex]);
new_inputs.emplace_back(in_tensor); new_inputs.emplace_back(in_tensor);
// create new weight // create new weight
@ -371,6 +378,7 @@ kernel::LiteKernel *CpuGroupConvInt8KernelCreator(const std::vector<lite::Tensor
MS_LOG(ERROR) << "create filter tensor failed."; MS_LOG(ERROR) << "create filter tensor failed.";
return nullptr; return nullptr;
} }
CopyTensorQuantParam(filter_tensor, inputs[kWeightIndex]);
new_inputs.emplace_back(filter_tensor); new_inputs.emplace_back(filter_tensor);
// if has bias, create new bias // if has bias, create new bias
@ -383,6 +391,7 @@ kernel::LiteKernel *CpuGroupConvInt8KernelCreator(const std::vector<lite::Tensor
MS_LOG(ERROR) << "create bias_tensor failed."; MS_LOG(ERROR) << "create bias_tensor failed.";
return nullptr; return nullptr;
} }
CopyTensorQuantParam(bias_tensor, inputs[kBiasIndex]);
new_inputs.emplace_back(bias_tensor); new_inputs.emplace_back(bias_tensor);
} }
@ -395,6 +404,7 @@ kernel::LiteKernel *CpuGroupConvInt8KernelCreator(const std::vector<lite::Tensor
MS_LOG(ERROR) << "new out_tensor failed."; MS_LOG(ERROR) << "new out_tensor failed.";
return nullptr; return nullptr;
} }
CopyTensorQuantParam(out_tensor, outputs[j]);
new_outputs.emplace_back(out_tensor); new_outputs.emplace_back(out_tensor);
} }
group_convs.emplace_back(CpuConvInt8KernelSelect( group_convs.emplace_back(CpuConvInt8KernelSelect(
@ -412,6 +422,15 @@ kernel::LiteKernel *CpuConvInt8KernelCreator(const std::vector<lite::Tensor *> &
MS_ASSERT(desc.type == schema::PrimitiveType_Conv2D); MS_ASSERT(desc.type == schema::PrimitiveType_Conv2D);
auto conv_param = reinterpret_cast<ConvParameter *>(opParameter); auto conv_param = reinterpret_cast<ConvParameter *>(opParameter);
kernel::LiteKernel *kernel = nullptr; kernel::LiteKernel *kernel = nullptr;
if (primitive != nullptr && primitive->infer_flag()) {
conv_param->input_h_ = inputs.front()->Height();
conv_param->input_w_ = inputs.front()->Width();
conv_param->input_channel_ = inputs.front()->Channel();
conv_param->output_h_ = outputs.front()->Height();
conv_param->output_w_ = outputs.front()->Width();
conv_param->output_channel_ = outputs.front()->Channel();
conv_param->op_parameter_.thread_num_ = ctx->thread_num_;
}
if (conv_param->group_ == 1) { if (conv_param->group_ == 1) {
kernel = CpuConvInt8KernelSelect(inputs, outputs, opParameter, ctx, primitive); kernel = CpuConvInt8KernelSelect(inputs, outputs, opParameter, ctx, primitive);
} else { } else {

@ -8,6 +8,8 @@ mobilenetv2-7.onnx
shufflenet-v2-10.onnx shufflenet-v2-10.onnx
squeezenet1.1-7.onnx squeezenet1.1-7.onnx
densenet-9.onnx densenet-9.onnx
ml_table_detection_fp32.onnx
ml_table_segment.onnx
googlenet-9.onnx googlenet-9.onnx
inception-v1-9.onnx inception-v1-9.onnx
inception-v2-9.onnx inception-v2-9.onnx

@ -8,6 +8,8 @@ mobilenetv2-7.onnx 8
shufflenet-v2-10.onnx 5 shufflenet-v2-10.onnx 5
squeezenet1.1-7.onnx 1 squeezenet1.1-7.onnx 1
densenet-9.onnx 6 densenet-9.onnx 6
ml_table_detection_fp32.onnx 2
ml_table_segment.onnx 2
googlenet-9.onnx 3 googlenet-9.onnx 3
inception-v1-9.onnx 3 inception-v1-9.onnx 3
inception-v2-9.onnx 4 inception-v2-9.onnx 4

@ -59,18 +59,27 @@ bool GroupDepthwiseOpConvertPass::Run(const FuncGraphPtr &graph) {
MS_LOG(DEBUG) << "the tensor's shape is dynamic."; MS_LOG(DEBUG) << "the tensor's shape is dynamic.";
return true; return true;
} }
auto conv_attr = std::make_unique<schema::Conv2DT>(); auto weight_data_node = depthwise_cnode->input(kConvWeightIndex)->abstract();
if (conv_attr == nullptr) { if (weight_data_node == nullptr) {
MS_LOG(ERROR) << "conv_attr is null"; MS_LOG(ERROR) << "the weight node input is invalid.";
return false; return false;
} }
auto weight_shape = utils::cast<abstract::ShapePtr>(weight_data_node->GetShapeTrack())->shape();
if (data_shape[3] == 1) { if (weight_shape.empty()) {
MS_LOG(DEBUG) << "the weight's shape is dynamic.";
return true;
}
if ((data_shape[3] == 1) || (data_shape[3] != weight_shape[3])) {
auto conv_attr = std::make_unique<schema::Conv2DT>();
if (conv_attr == nullptr) {
MS_LOG(ERROR) << "conv_attr is null";
return false;
}
conv_attr->channelIn = data_shape[3]; conv_attr->channelIn = data_shape[3];
conv_attr->channelOut = conv_attr->channelIn * attr->channelMultiplier; conv_attr->channelOut = weight_shape[3];
// update attr // update attr
conv_attr->group = 1; conv_attr->group = data_shape[3];
conv_attr->format = attr->format; conv_attr->format = attr->format;
conv_attr->kernelH = attr->kernelH; conv_attr->kernelH = attr->kernelH;
conv_attr->kernelW = attr->kernelW; conv_attr->kernelW = attr->kernelW;

Loading…
Cancel
Save