diff --git a/x2paddle/convert.py b/x2paddle/convert.py index d5c78e761ce1aa88e67a4405074fccb28ad1d727..86f62104e03a837041660e8ff4e161b6d7160f8c 100644 --- a/x2paddle/convert.py +++ b/x2paddle/convert.py @@ -190,6 +190,7 @@ def onnx2paddle(model_path, save_dir, params_merge=False): mapper = ONNXOpMapper(model) print("Model optimizing ...") optimizer = ONNXOptimizer(mapper) + optimizer.delete_redundance_code() print("Model optimized.") print("Paddle model and code generating ...") diff --git a/x2paddle/op_mapper/onnx2paddle/opset9/opset.py b/x2paddle/op_mapper/onnx2paddle/opset9/opset.py index 38087558f6099b46ba15e3d1ee230b3f2c9a24cb..b36560c1888cc30980bfc5e8727167c09dcb7b92 100644 --- a/x2paddle/op_mapper/onnx2paddle/opset9/opset.py +++ b/x2paddle/op_mapper/onnx2paddle/opset9/opset.py @@ -1256,10 +1256,19 @@ class OpSet9(): mode = 'channel' shape_slope = val_slope.out_shapes[0] - if len(shape_slope) == 1: + + if shape_slope == [1]: mode = 'all' elif len(shape_slope) > 2: mode = 'element' + + if mode == 'channel' and len(shape_slope) == 1: + # paddle params shape need be [1, channel] + slope_data = _const_weight_or_none(val_slope) + slope_data = np.reshape(slope_data, [1] + shape_slope) + self.weights[val_slope.layer_name] = slope_data + + self.omit_nodes.append(val_slope.layer_name) attr = { "param_attr": string(val_slope.layer_name), 'mode': string(mode)