From 93d89e3d526ff9ac23b802fd8e08232edb819cfd Mon Sep 17 00:00:00 2001 From: "man.lu" Date: Mon, 9 Jan 2023 04:27:47 +0000 Subject: [PATCH] Fix PReluOp weight mapping bug in CodeGen. 1. The backend of PReluOp uses stride descriptions to represent data, so we should not align with the EU number. (loc: nodechip_prelu_local.c:36) Change-Id: I18e903acaebaf35e5762c76df973d7e1e978f8f9 --- .../Transforms/LayerGroup/LayerGroupUtil.cpp | 3 ++- python/test/test_onnx.py | 17 +++++++++-------- python/transform/CaffeConverter.py | 2 -- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/Dialect/Tpu/Transforms/LayerGroup/LayerGroupUtil.cpp b/lib/Dialect/Tpu/Transforms/LayerGroup/LayerGroupUtil.cpp index cbcf497bd..af6af6bc2 100644 --- a/lib/Dialect/Tpu/Transforms/LayerGroup/LayerGroupUtil.cpp +++ b/lib/Dialect/Tpu/Transforms/LayerGroup/LayerGroupUtil.cpp @@ -492,7 +492,8 @@ bool is_eu_align(Value opd) { // Eu align rule may be different in different platforms auto op = *opd.getUsers().begin(); if (isWeightValue(opd)) { - if (isa(op) && + if (isa(op) && (opd == op->getOperand(1) || opd == op->getOperand(2))) { return false; } diff --git a/python/test/test_onnx.py b/python/test/test_onnx.py index 36d41d006..b71e2cae7 100755 --- a/python/test/test_onnx.py +++ b/python/test/test_onnx.py @@ -2401,14 +2401,15 @@ def test_Reciprocal(self, case_name): self.onnx_and_test(graph_def, input_data={"input": input_data}) def test_PRelu(self, case_name): - input_shape = [3, 5, 100, 100] - slope_shape = [1, 5, 1, 1] - output_shape = [3, 5, 100, 100] - slope = helper.make_tensor(name='slope', - data_type=onnx.TensorProto.FLOAT, - dims=slope_shape, - vals=[0.40, 0.37, 0.31, 0.19, 0.11]) - + input_shape = [3, 128, 100, 100] + slope_shape = [1, 128, 1, 1] + output_shape = [3, 128, 100, 100] + slope = helper.make_tensor( + name="slope", + data_type=onnx.TensorProto.FLOAT, + dims=slope_shape, + vals=np.random.rand(*slope_shape).astype(np.float32), + ) inputs = [helper.make_tensor_value_info("input", TensorProto.FLOAT, input_shape)] outputs = [helper.make_tensor_value_info('output', TensorProto.FLOAT, output_shape)] prelu_def = helper.make_node("PRelu", ["input", "slope"], ["output"]) diff --git a/python/transform/CaffeConverter.py b/python/transform/CaffeConverter.py index 63772ff55..bf064c8eb 100644 --- a/python/transform/CaffeConverter.py +++ b/python/transform/CaffeConverter.py @@ -336,8 +336,6 @@ def convert_scale_op(self, layer): output_shape = input_shape attrs = {'name': self.get_loc(layer.top[0])} assert (num_dims == 4 or num_dims == 2) - if num_dims == 2: - raise RuntimeError("Not support now, shape {}".format(input_shape)) if len(layer.bottom) == 2: op1 = self.getOperand(layer.bottom[1]) input_shape1 = self.getShape(layer.bottom[1])