diff --git a/x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py b/x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py index bfeb120b6a30d2b6d2861715c7b9276ad8d4ab4f..599099a3905b2b2a8674198e3dab0345feadee72 100644 --- a/x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py +++ b/x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py @@ -1359,21 +1359,49 @@ class OpSet9(): elif len(shape_slope) > 2: raise Exception("The 'element' mode is not supported yet!") - 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.name] = slope_data - num_parameters = val_x.out_shapes[0][1] + if mode == "element": + self.paddle_graph.add_layer( + "paddle.zeros", + inputs={}, + outputs=[output_name + "__zeros"], + shape=shape_slope, + dtype=string(node.dtype)) + self.paddle_graph.add_layer( + "paddle.maximum", + inputs={"x": val_x.name, + "y": output_name + "__zeros"}, + outputs=[output_name + "__max"]) + self.paddle_graph.add_layer( + "paddle.minimum", + inputs={"x": val_x.name, + "y": output_name + "__zeros"}, + outputs=[output_name + "__max"]) + self.paddle_graph.add_layer( + "paddle.multiply", + inputs={"x": val_slope.name, + "y": output_name + "__min"}, + outputs=[output_name + "__mul"]) + self.paddle_graph.add_layer( + "paddle.add", + inputs={"x": output_name + "__max", + "y": output_name + "__mul"}, + outputs=[output_name]) else: - num_parameters = 1 + 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.name] = slope_data + num_parameters = val_x.out_shapes[0][1] + else: + num_parameters = 1 - self.paddle_graph.add_layer( - "paddle.nn.PReLU", - inputs={"x": val_x.name}, - outputs=layer_outputs, - num_parameters=num_parameters, - weight_attr=string(val_slope.name)) + self.paddle_graph.add_layer( + "paddle.nn.PReLU", + inputs={"x": val_x.name}, + outputs=layer_outputs, + num_parameters=num_parameters, + weight_attr=string(val_slope.name)) @print_mapping_info def Squeeze(self, node): diff --git a/x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py b/x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py index aab454088319d0019712fb2c90c5f41ed36366ab..da88009c8c4f2ec57fe47b31b1fe3732f460a143 100644 --- a/x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py +++ b/x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py @@ -1336,17 +1336,25 @@ class OpSet9(): elif len(shape_slope) > 2: raise Exception("The 'element' mode is not supported yet!") - 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.params[val_slope.name] = slope_data - - self.paddle_graph.add_layer( - "paddle.nn.functional.prelu", - inputs={"x": val_x.name, - "weight": val_slope.name}, - outputs=[node.name]) + if mode == "element": + self.paddle_graph.add_layer( + "paddle.static.nn.prelu", + inputs={"x": val_x.name, + "param_attr": val_slope.name}, + outputs=[node.name], + mode="element") + else: + 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.params[val_slope.name] = slope_data + + self.paddle_graph.add_layer( + "paddle.nn.functional.prelu", + inputs={"x": val_x.name, + "weight": val_slope.name}, + outputs=[node.name]) @print_mapping_info def Squeeze(self, node):