diff --git a/tests/onnx/test_auto_scan_conv2d.py b/tests/onnx/test_auto_scan_conv2d.py index 17fd856ed940d7c460b96e76f2ef6850e1d2694c..74f86c93093a1e048f30385534569359f77ea882 100644 --- a/tests/onnx/test_auto_scan_conv2d.py +++ b/tests/onnx/test_auto_scan_conv2d.py @@ -99,7 +99,7 @@ class TestConv2dConvert(OPConvertAutoScanTest): "inputs_shape": [[-1, input_shape[1], -1, -1], kernel_size], "outputs_shape": [[-1, kernel_size[0], -1, -1]], "outputs_dtype": [['float32']], - "opset_version": [7, 9], + "opset_version": [7, 9, 14], "inputs_name": ["x", "W"], "outputs_name": ["y"], "delta": 1e-4, diff --git a/x2paddle/op_mapper/onnx2paddle/onnx_op_mapper.py b/x2paddle/op_mapper/onnx2paddle/onnx_op_mapper.py index 4838b744db04cea5d8cff8c51418f8cd65a9ef4f..7a0ec49a78bb8612fad5b1953eb23f980c540673 100644 --- a/x2paddle/op_mapper/onnx2paddle/onnx_op_mapper.py +++ b/x2paddle/op_mapper/onnx2paddle/onnx_op_mapper.py @@ -13,14 +13,14 @@ # limitations under the License. import sys -from x2paddle.op_mapper.onnx2paddle.opset9 import OpSet9 +from x2paddle.op_mapper.onnx2paddle.opset import OpSet7, OpSet8, OpSet9, OpSet10, OpSet11, OpSet12, OpSet13, OpSet14, OpSet15 from x2paddle.decoder.onnx_decoder import ONNXGraphNode from x2paddle.core.program import PaddleGraph class ONNXOpMapper(): def __init__(self, decoder): - self.support_op_sets = [9, ] + self.support_op_sets = [7, 8, 9, 10, 11, 12, 13, 14, 15] self.default_op_set = 9 self.graph = decoder.graph self.paddle_graph = PaddleGraph(parent_layer=None, source_type="onnx") @@ -84,8 +84,7 @@ class ONNXOpMapper(): else: break opset = 'OpSet' + str(run_op_set) - print( - 'Now, onnx2paddle support convert onnx model opset_verison {},' - 'opset_verison of your onnx model is {}, automatically treated as op_set: {}.' - .format(self.support_op_sets, decoder.op_set, run_op_set)) + print('Now, onnx2paddle support convert onnx model opset_verison {},' + 'opset_verison of your onnx model is {}.' + .format(self.support_op_sets, decoder.op_set)) return eval(opset)(decoder, self.paddle_graph) diff --git a/x2paddle/op_mapper/onnx2paddle/opset/__init__.py b/x2paddle/op_mapper/onnx2paddle/opset/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..262ec61be57029c5efb5d1e3fd854640758f4455 --- /dev/null +++ b/x2paddle/op_mapper/onnx2paddle/opset/__init__.py @@ -0,0 +1,9 @@ +from .opset7 import OpSet7 +from .opset8 import OpSet8 +from .opset9 import OpSet9 +from .opset10 import OpSet10 +from .opset11 import OpSet11 +from .opset12 import OpSet12 +from .opset13 import OpSet13 +from .opset14 import OpSet14 +from .opset15 import OpSet15 diff --git a/x2paddle/op_mapper/onnx2paddle/opset9/opset.py b/x2paddle/op_mapper/onnx2paddle/opset/opset.py similarity index 97% rename from x2paddle/op_mapper/onnx2paddle/opset9/opset.py rename to x2paddle/op_mapper/onnx2paddle/opset/opset.py index 82beecc355ed607ac67b26ab83803eadd8925c5b..ac3035a918e7e5de5a317242d73889562116baf2 100755 --- a/x2paddle/op_mapper/onnx2paddle/opset9/opset.py +++ b/x2paddle/op_mapper/onnx2paddle/opset/opset.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License" # you may not use this file except in compliance with the License. @@ -117,74 +117,9 @@ def print_mapping_info(func): return run_mapping -class OpSet9(): - elementwise_ops = { - 'Add': 'paddle.add', - 'Div': 'paddle.divide', - 'Sub': 'paddle.subtract', - 'Mul': 'paddle.multiply', - 'Pow': 'paddle.pow', - 'Less': 'paddle.less_than', - 'LessOrEqual': 'paddle.less_equal', - } - - directly_map_ops = { - 'Ceil': ['paddle.ceil'], - # reduce function - 'ReduceMean': [ - 'paddle.mean', dict( - axes='axis', keepdims='keepdim'), dict( - axes=None, keepdims=True) - ], - 'ReduceMin': [ - 'paddle.min', dict( - axes='axis', keepdims='keepdim'), dict( - axes=None, keepdim=True) - ], - 'ReduceMax': [ - 'paddle.max', dict( - axes='axis', keepdims='keepdim'), dict( - axes=None, keepdim=True) - ], - 'ReduceProd': [ - 'paddle.prod', dict( - axes='axis', keepdims='keepdim'), dict( - axes=None, keepdim=True) - ], - # active function - 'Relu': ['paddle.nn.ReLU'], - 'LeakyRelu': [ - 'paddle.nn.LeakyReLU', dict(alpha='negative_slope'), - dict(negative_slope=.01) - ], - 'Elu': - ['paddle.nn.functional.elu', dict(alpha='alpha'), dict(alpha=1.)], - 'ThresholdedRelu': [ - 'paddle.nn.functional.thresholded_relu', dict(alpha='threshold'), - dict(alpha=1.) - ], - 'Tanh': ['paddle.nn.Tanh'], - 'Sigmoid': ['paddle.nn.Sigmoid'], - 'Softsign': ['paddle.nn.Softsign'], - 'Softplus': [ - 'paddle.nn.Softplus', dict(threshold='threshold'), - dict(threshold=float(sys.maxsize)) - ], - 'Exp': ['paddle.exp'], - 'Log': ['paddle.log'], - 'LogSoftmax': - ['paddle.nn.functional.log_softmax', dict(axis='axis'), dict(axis=1)], - 'Softmax': ['paddle.nn.Softmax', dict(axis='axis'), dict(axis=1)], - 'Sqrt': ['paddle.sqrt'], - 'Floor': ['paddle.floor'], - 'Abs': ['paddle.abs'], - 'Erf': ['paddle.erf'], - 'Sin': ['paddle.sin'], - 'Cos': ['paddle.cos'], - } - +class OpSet(): def __init__(self, decoder, paddle_graph): - super(OpSet9, self).__init__() + super(OpSet, self).__init__() self.graph = decoder.graph self.paddle_graph = paddle_graph self.inputs_info = dict() @@ -194,6 +129,72 @@ class OpSet9(): # solve for same data is used as an argument to multiple OPs. # PR link(wangjunjie06): https://github.com/PaddlePaddle/X2Paddle/pull/728 self.rename_mapper = dict() + self.elementwise_ops = { + 'Add': 'paddle.add', + 'Div': 'paddle.divide', + 'Sub': 'paddle.subtract', + 'Mul': 'paddle.multiply', + 'Pow': 'paddle.pow', + 'Less': 'paddle.less_than', + 'LessOrEqual': 'paddle.less_equal', + } + + self.directly_map_ops = { + 'Ceil': ['paddle.ceil'], + # reduce function + 'ReduceMean': [ + 'paddle.mean', dict( + axes='axis', keepdims='keepdim'), dict( + axes=None, keepdims=True) + ], + 'ReduceMin': [ + 'paddle.min', dict( + axes='axis', keepdims='keepdim'), dict( + axes=None, keepdim=True) + ], + 'ReduceMax': [ + 'paddle.max', dict( + axes='axis', keepdims='keepdim'), dict( + axes=None, keepdim=True) + ], + 'ReduceProd': [ + 'paddle.prod', dict( + axes='axis', keepdims='keepdim'), dict( + axes=None, keepdim=True) + ], + # active function + 'Relu': ['paddle.nn.ReLU'], + 'LeakyRelu': [ + 'paddle.nn.LeakyReLU', dict(alpha='negative_slope'), + dict(negative_slope=.01) + ], + 'Elu': + ['paddle.nn.functional.elu', dict(alpha='alpha'), dict(alpha=1.)], + 'ThresholdedRelu': [ + 'paddle.nn.functional.thresholded_relu', + dict(alpha='threshold'), dict(alpha=1.) + ], + 'Tanh': ['paddle.nn.Tanh'], + 'Sigmoid': ['paddle.nn.Sigmoid'], + 'Softsign': ['paddle.nn.Softsign'], + 'Softplus': [ + 'paddle.nn.Softplus', dict(threshold='threshold'), + dict(threshold=float(sys.maxsize)) + ], + 'Exp': ['paddle.exp'], + 'Log': ['paddle.log'], + 'LogSoftmax': [ + 'paddle.nn.functional.log_softmax', dict(axis='axis'), + dict(axis=1) + ], + 'Softmax': ['paddle.nn.Softmax', dict(axis='axis'), dict(axis=1)], + 'Sqrt': ['paddle.sqrt'], + 'Floor': ['paddle.floor'], + 'Abs': ['paddle.abs'], + 'Erf': ['paddle.erf'], + 'Sin': ['paddle.sin'], + 'Cos': ['paddle.cos'], + } @print_mapping_info def directly_map(self, node, *args, **kwargs): diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset10.py b/x2paddle/op_mapper/onnx2paddle/opset/opset10.py new file mode 100644 index 0000000000000000000000000000000000000000..93fb3d14d5ba2f8ba59d50e70394a247ec5ad923 --- /dev/null +++ b/x2paddle/op_mapper/onnx2paddle/opset/opset10.py @@ -0,0 +1,20 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License" +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .opset import OpSet + + +class OpSet10(OpSet): + def __init__(self, decoder, paddle_graph): + super(OpSet10, self).__init__(decoder, paddle_graph) diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset11.py b/x2paddle/op_mapper/onnx2paddle/opset/opset11.py new file mode 100644 index 0000000000000000000000000000000000000000..fb2499890e4c11e1eb45579952abea90ffb3e815 --- /dev/null +++ b/x2paddle/op_mapper/onnx2paddle/opset/opset11.py @@ -0,0 +1,20 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License" +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .opset import OpSet + + +class OpSet11(OpSet): + def __init__(self, decoder, paddle_graph): + super(OpSet11, self).__init__(decoder, paddle_graph) diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset12.py b/x2paddle/op_mapper/onnx2paddle/opset/opset12.py new file mode 100644 index 0000000000000000000000000000000000000000..8c6bde30d5b59e9cd3e388b4abc145a8d048faf4 --- /dev/null +++ b/x2paddle/op_mapper/onnx2paddle/opset/opset12.py @@ -0,0 +1,20 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License" +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .opset import OpSet + + +class OpSet12(OpSet): + def __init__(self, decoder, paddle_graph): + super(OpSet12, self).__init__(decoder, paddle_graph) diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset13.py b/x2paddle/op_mapper/onnx2paddle/opset/opset13.py new file mode 100644 index 0000000000000000000000000000000000000000..e851951aa5eaa8905c3b9a59f78478a474e93c90 --- /dev/null +++ b/x2paddle/op_mapper/onnx2paddle/opset/opset13.py @@ -0,0 +1,20 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License" +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .opset import OpSet + + +class OpSet13(OpSet): + def __init__(self, decoder, paddle_graph): + super(OpSet13, self).__init__(decoder, paddle_graph) diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset14.py b/x2paddle/op_mapper/onnx2paddle/opset/opset14.py new file mode 100644 index 0000000000000000000000000000000000000000..f12dbad4d47d81751154ac0d4326249c93f76b53 --- /dev/null +++ b/x2paddle/op_mapper/onnx2paddle/opset/opset14.py @@ -0,0 +1,20 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License" +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .opset import OpSet + + +class OpSet14(OpSet): + def __init__(self, decoder, paddle_graph): + super(OpSet14, self).__init__(decoder, paddle_graph) diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset15.py b/x2paddle/op_mapper/onnx2paddle/opset/opset15.py new file mode 100644 index 0000000000000000000000000000000000000000..e0dede2e4b533a4b6052aae10576b14625491bd0 --- /dev/null +++ b/x2paddle/op_mapper/onnx2paddle/opset/opset15.py @@ -0,0 +1,20 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License" +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .opset import OpSet + + +class OpSet15(OpSet): + def __init__(self, decoder, paddle_graph): + super(OpSet15, self).__init__(decoder, paddle_graph) diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset7.py b/x2paddle/op_mapper/onnx2paddle/opset/opset7.py new file mode 100644 index 0000000000000000000000000000000000000000..127e8179e55275d80f2e9a2c42711d80db8189a8 --- /dev/null +++ b/x2paddle/op_mapper/onnx2paddle/opset/opset7.py @@ -0,0 +1,20 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License" +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .opset import OpSet + + +class OpSet7(OpSet): + def __init__(self, decoder, paddle_graph): + super(OpSet7, self).__init__(decoder, paddle_graph) diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset8.py b/x2paddle/op_mapper/onnx2paddle/opset/opset8.py new file mode 100644 index 0000000000000000000000000000000000000000..0ea01f90a68a48b18e569dfc479ecc34377c93c5 --- /dev/null +++ b/x2paddle/op_mapper/onnx2paddle/opset/opset8.py @@ -0,0 +1,20 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License" +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .opset import OpSet + + +class OpSet8(OpSet): + def __init__(self, decoder, paddle_graph): + super(OpSet8, self).__init__(decoder, paddle_graph) diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset9.py b/x2paddle/op_mapper/onnx2paddle/opset/opset9.py new file mode 100644 index 0000000000000000000000000000000000000000..3d408231fd5cde7aae654afb70762d7eed0df983 --- /dev/null +++ b/x2paddle/op_mapper/onnx2paddle/opset/opset9.py @@ -0,0 +1,20 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License" +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .opset import OpSet + + +class OpSet9(OpSet): + def __init__(self, decoder, paddle_graph): + super(OpSet9, self).__init__(decoder, paddle_graph) diff --git a/x2paddle/op_mapper/onnx2paddle/opset9/__init__.py b/x2paddle/op_mapper/onnx2paddle/opset9/__init__.py deleted file mode 100644 index 0092e6e24986576fba653f47bd99342eb9995a27..0000000000000000000000000000000000000000 --- a/x2paddle/op_mapper/onnx2paddle/opset9/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .opset import OpSet9