From 11f41a1c160f6ed2b8b810c121e01f2d52f8525e Mon Sep 17 00:00:00 2001 From: wjj19950828 Date: Tue, 2 Aug 2022 14:24:55 +0800 Subject: [PATCH] add Or and Xor --- docs/inference_model_convertor/op_list.md | 2 +- tests/onnx/test_auto_scan_logical_ops.py | 4 +++- x2paddle/op_mapper/onnx2paddle/opset7.py | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/docs/inference_model_convertor/op_list.md b/docs/inference_model_convertor/op_list.md index b7d19c2..7925eab 100755 --- a/docs/inference_model_convertor/op_list.md +++ b/docs/inference_model_convertor/op_list.md @@ -76,7 +76,7 @@ | 81 | Add | 82 | Concat | 83 | Max | 84 | Min | | 85 | GreaterOrEqual | 86 | GatherND | 87 | And | 88 | cos | | 89 | Neg | 90 | SpaceToDepth | 91 | GatherElement | 92 | Sin | -| 93 | CumSum | | | | | | | +| 93 | CumSum | 94 | Or | 95 | Xor | | | ## PyTorch diff --git a/tests/onnx/test_auto_scan_logical_ops.py b/tests/onnx/test_auto_scan_logical_ops.py index c6fa112..d7f9f23 100644 --- a/tests/onnx/test_auto_scan_logical_ops.py +++ b/tests/onnx/test_auto_scan_logical_ops.py @@ -21,6 +21,8 @@ import unittest min_opset_version_map = { "And": 7, + "Or": 7, + "Xor": 7, } @@ -47,7 +49,7 @@ class TestLogicalopsConvert(OPConvertAutoScanTest): input_dtype = draw(st.sampled_from(["bool"])) config = { - "op_names": ["And"], + "op_names": ["And", "Or", "Xor"], "test_data_shapes": [input1_shape, input2_shape], "test_data_types": [[input_dtype], [input_dtype]], "inputs_shape": [], diff --git a/x2paddle/op_mapper/onnx2paddle/opset7.py b/x2paddle/op_mapper/onnx2paddle/opset7.py index 4444465..6c0c22e 100644 --- a/x2paddle/op_mapper/onnx2paddle/opset7.py +++ b/x2paddle/op_mapper/onnx2paddle/opset7.py @@ -33,6 +33,26 @@ class OpSet7(OpSet): def __init__(self, decoder, paddle_graph): super(OpSet7, self).__init__(decoder, paddle_graph) + @print_mapping_info + def Or(self, node): + val_x = self.graph.get_input_node(node, idx=0, copy=True) + val_y = self.graph.get_input_node(node, idx=1, copy=True) + self.paddle_graph.add_layer( + "paddle.logical_or", + inputs={"x": val_x.name, + "y": val_y.name}, + outputs=[node.name]) + + @print_mapping_info + def Xor(self, node): + val_x = self.graph.get_input_node(node, idx=0, copy=True) + val_y = self.graph.get_input_node(node, idx=1, copy=True) + self.paddle_graph.add_layer( + "paddle.logical_xor", + inputs={"x": val_x.name, + "y": val_y.name}, + outputs=[node.name]) + @print_mapping_info def Unsqueeze(self, node): val_x = self.graph.get_input_node(node, idx=0, copy=True) -- GitLab