From 84d2a1b8553ada871750676919289e7e5e19addf Mon Sep 17 00:00:00 2001 From: shitouren1994 <49087929+shitouren1994@users.noreply.github.com> Date: Fri, 17 Sep 2021 14:25:55 +0800 Subject: [PATCH] bug fix (#1142) * bug fix 1.eltwise div error 2.instancenorm w==0 error fix 3.onnx2tengine deconv output channel error * apply code-format changes Co-authored-by: shitouren1994 --- source/device/cpu/op/eltwise/eltwise_ref.c | 10 ++++++++++ source/device/cpu/op/instancenorm/instancenorm_ref.c | 5 +++++ tools/convert_tool/onnx/onnx2tengine.cpp | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/source/device/cpu/op/eltwise/eltwise_ref.c b/source/device/cpu/op/eltwise/eltwise_ref.c index 63f4f9a3..216ec385 100644 --- a/source/device/cpu/op/eltwise/eltwise_ref.c +++ b/source/device/cpu/op/eltwise/eltwise_ref.c @@ -223,6 +223,16 @@ static int ref_eltwise_fp32(void* output, void* input0, void* input1, int type, *out_ptr++ = in0[i] / in1[i / input_hw]; } } + else if (input_hw == input_hw_1) + { + for (int i = 0; i < input_chan; i++) + { + for (int j = 0; j < input_hw; j++) + { + *out_ptr++ = in0[i * input_hw + j] / in1[j]; + } + } + } else { break; diff --git a/source/device/cpu/op/instancenorm/instancenorm_ref.c b/source/device/cpu/op/instancenorm/instancenorm_ref.c index b18a84fc..94d943af 100644 --- a/source/device/cpu/op/instancenorm/instancenorm_ref.c +++ b/source/device/cpu/op/instancenorm/instancenorm_ref.c @@ -198,6 +198,11 @@ static int run(struct node_ops* node_ops, struct exec_node* exec_node, struct ex int h = input_tensor->dims[2]; int w = input_tensor->dims[3]; + if (w == 0) + { + w = 1; + } + int size = w * h; void* in_data = input_tensor->data; diff --git a/tools/convert_tool/onnx/onnx2tengine.cpp b/tools/convert_tool/onnx/onnx2tengine.cpp index d58a0e52..17627d1a 100644 --- a/tools/convert_tool/onnx/onnx2tengine.cpp +++ b/tools/convert_tool/onnx/onnx2tengine.cpp @@ -2008,7 +2008,8 @@ static int load_deconv(ir_graph_t* graph, ir_node_t* node, const onnx::NodeProto { int* dim = tensor->dims; /* onnx hide the output channel in weight ..*/ - deconv_param->num_output = dim[1]; + /* The number of channels in the output should be equal to W.shape[1] * group */ + deconv_param->num_output = dim[1] * deconv_param->group; deconv_param->kernel_h = dim[2]; deconv_param->kernel_w = dim[3]; } -- GitLab