diff --git a/docs/pytorch_project_convertor/API_docs/vision/torchvision.utils.save_image.md b/docs/pytorch_project_convertor/API_docs/vision/torchvision.utils.save_image.md index 3a5096b04a6ef1cfba39a610e080a23e8170cd29..4bf2458c56e47bd4ea2967f71e0251eadbf4bf8c 100644 --- a/docs/pytorch_project_convertor/API_docs/vision/torchvision.utils.save_image.md +++ b/docs/pytorch_project_convertor/API_docs/vision/torchvision.utils.save_image.md @@ -46,11 +46,10 @@ def make_grid(tensor: Union[paddle.Tensor, List[paddle.Tensor]], if tensor.dim() == 2: # single image H x W tensor = tensor.unsqueeze(0) if tensor.dim() == 3: # single image - if tensor.size(0) == 1: # if single-channel, convert to 3-channel + if tensor.shape[0] == 1: # if single-channel, convert to 3-channel tensor = paddle.concat((tensor, tensor, tensor), 0) tensor = tensor.unsqueeze(0) - - if tensor.dim() == 4 and tensor.size(1) == 1: # single-channel images + if tensor.dim() == 4 and tensor.shape[1] == 1: # single-channel images tensor = paddle.concat((tensor, tensor, tensor), 1) if normalize is True: @@ -75,11 +74,11 @@ def make_grid(tensor: Union[paddle.Tensor, List[paddle.Tensor]], else: norm_range(tensor, value_range) - if tensor.size(0) == 1: + if tensor.shape[0] == 1: return tensor.squeeze(0) # make the mini-batch of images into a grid - nmaps = tensor.size(0) + nmaps = tensor.shape[0] xmaps = min(nrow, nmaps) ymaps = int(math.ceil(float(nmaps) / xmaps)) height, width = int(tensor.shape[2] + padding), int(tensor.shape[3] + diff --git a/x2paddle/__init__.py b/x2paddle/__init__.py index e5dfa7e74e93c4a8104755d394c1670cc6dd6077..e70229eb8843b23b84e687cc4be86cfdeeaa8436 100644 --- a/x2paddle/__init__.py +++ b/x2paddle/__init__.py @@ -1,4 +1,4 @@ -__version__ = "1.3.7" +__version__ = "1.3.8" from .core.program import PaddleGraph diff --git a/x2paddle/op_mapper/onnx2paddle/onnx_op_mapper.py b/x2paddle/op_mapper/onnx2paddle/onnx_op_mapper.py index 28ff1d35e2fee3db4dc6234f36fd9510b1d77be3..25724ecbecd3eb3e863174ee2c9cdca91f1482fa 100644 --- a/x2paddle/op_mapper/onnx2paddle/onnx_op_mapper.py +++ b/x2paddle/op_mapper/onnx2paddle/onnx_op_mapper.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. @@ -13,7 +13,15 @@ # limitations under the License. import sys -from x2paddle.op_mapper.onnx2paddle.opset import OpSet7, OpSet8, OpSet9, OpSet10, OpSet11, OpSet12, OpSet13, OpSet14, OpSet15 +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 from x2paddle.decoder.onnx_decoder import ONNXGraphNode from x2paddle.core.program import PaddleGraph diff --git a/x2paddle/op_mapper/onnx2paddle/opset/__init__.py b/x2paddle/op_mapper/onnx2paddle/opset/__init__.py deleted file mode 100644 index 262ec61be57029c5efb5d1e3fd854640758f4455..0000000000000000000000000000000000000000 --- a/x2paddle/op_mapper/onnx2paddle/opset/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -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/opset/opset10.py b/x2paddle/op_mapper/onnx2paddle/opset10.py similarity index 95% rename from x2paddle/op_mapper/onnx2paddle/opset/opset10.py rename to x2paddle/op_mapper/onnx2paddle/opset10.py index 93fb3d14d5ba2f8ba59d50e70394a247ec5ad923..b27f697a6508c234691431a4a3622f60b3628e52 100644 --- a/x2paddle/op_mapper/onnx2paddle/opset/opset10.py +++ b/x2paddle/op_mapper/onnx2paddle/opset10.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .opset import OpSet +from .opset_legacy import OpSet class OpSet10(OpSet): diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset11.py b/x2paddle/op_mapper/onnx2paddle/opset11.py similarity index 95% rename from x2paddle/op_mapper/onnx2paddle/opset/opset11.py rename to x2paddle/op_mapper/onnx2paddle/opset11.py index fb2499890e4c11e1eb45579952abea90ffb3e815..8e57c462df9bb7159c7d7b31f235e189d122ecb4 100644 --- a/x2paddle/op_mapper/onnx2paddle/opset/opset11.py +++ b/x2paddle/op_mapper/onnx2paddle/opset11.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .opset import OpSet +from .opset_legacy import OpSet class OpSet11(OpSet): diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset12.py b/x2paddle/op_mapper/onnx2paddle/opset12.py similarity index 95% rename from x2paddle/op_mapper/onnx2paddle/opset/opset12.py rename to x2paddle/op_mapper/onnx2paddle/opset12.py index 8c6bde30d5b59e9cd3e388b4abc145a8d048faf4..bcf94f222879901381b762024318019869919127 100644 --- a/x2paddle/op_mapper/onnx2paddle/opset/opset12.py +++ b/x2paddle/op_mapper/onnx2paddle/opset12.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .opset import OpSet +from .opset_legacy import OpSet class OpSet12(OpSet): diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset13.py b/x2paddle/op_mapper/onnx2paddle/opset13.py similarity index 95% rename from x2paddle/op_mapper/onnx2paddle/opset/opset13.py rename to x2paddle/op_mapper/onnx2paddle/opset13.py index e851951aa5eaa8905c3b9a59f78478a474e93c90..2b640a4c55b3ad585d2cbf4bf21ac33821227dad 100644 --- a/x2paddle/op_mapper/onnx2paddle/opset/opset13.py +++ b/x2paddle/op_mapper/onnx2paddle/opset13.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .opset import OpSet +from .opset_legacy import OpSet class OpSet13(OpSet): diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset14.py b/x2paddle/op_mapper/onnx2paddle/opset14.py similarity index 95% rename from x2paddle/op_mapper/onnx2paddle/opset/opset14.py rename to x2paddle/op_mapper/onnx2paddle/opset14.py index f12dbad4d47d81751154ac0d4326249c93f76b53..dedfc7fe3f88ffa640a54fff6875e74028b30a3c 100644 --- a/x2paddle/op_mapper/onnx2paddle/opset/opset14.py +++ b/x2paddle/op_mapper/onnx2paddle/opset14.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .opset import OpSet +from .opset_legacy import OpSet class OpSet14(OpSet): diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset15.py b/x2paddle/op_mapper/onnx2paddle/opset15.py similarity index 95% rename from x2paddle/op_mapper/onnx2paddle/opset/opset15.py rename to x2paddle/op_mapper/onnx2paddle/opset15.py index e0dede2e4b533a4b6052aae10576b14625491bd0..67bdc00161c4483a5c1ae2e4a600f8aba885570f 100644 --- a/x2paddle/op_mapper/onnx2paddle/opset/opset15.py +++ b/x2paddle/op_mapper/onnx2paddle/opset15.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .opset import OpSet +from .opset_legacy import OpSet class OpSet15(OpSet): diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset7.py b/x2paddle/op_mapper/onnx2paddle/opset7.py similarity index 95% rename from x2paddle/op_mapper/onnx2paddle/opset/opset7.py rename to x2paddle/op_mapper/onnx2paddle/opset7.py index 127e8179e55275d80f2e9a2c42711d80db8189a8..befa14ef65392a62804412e2d3178cd39302abc7 100644 --- a/x2paddle/op_mapper/onnx2paddle/opset/opset7.py +++ b/x2paddle/op_mapper/onnx2paddle/opset7.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .opset import OpSet +from .opset_legacy import OpSet class OpSet7(OpSet): diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset8.py b/x2paddle/op_mapper/onnx2paddle/opset8.py similarity index 95% rename from x2paddle/op_mapper/onnx2paddle/opset/opset8.py rename to x2paddle/op_mapper/onnx2paddle/opset8.py index 0ea01f90a68a48b18e569dfc479ecc34377c93c5..e59cbc000b1dd13a1ec5412c82bbf457e7bdbbbd 100644 --- a/x2paddle/op_mapper/onnx2paddle/opset/opset8.py +++ b/x2paddle/op_mapper/onnx2paddle/opset8.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .opset import OpSet +from .opset_legacy import OpSet class OpSet8(OpSet): diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset9.py b/x2paddle/op_mapper/onnx2paddle/opset9.py similarity index 95% rename from x2paddle/op_mapper/onnx2paddle/opset/opset9.py rename to x2paddle/op_mapper/onnx2paddle/opset9.py index 3d408231fd5cde7aae654afb70762d7eed0df983..a67821b7eaa56ea71e092fde23d28888a485171b 100644 --- a/x2paddle/op_mapper/onnx2paddle/opset/opset9.py +++ b/x2paddle/op_mapper/onnx2paddle/opset9.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .opset import OpSet +from .opset_legacy import OpSet class OpSet9(OpSet): diff --git a/x2paddle/op_mapper/onnx2paddle/opset/opset.py b/x2paddle/op_mapper/onnx2paddle/opset_legacy.py old mode 100755 new mode 100644 similarity index 100% rename from x2paddle/op_mapper/onnx2paddle/opset/opset.py rename to x2paddle/op_mapper/onnx2paddle/opset_legacy.py diff --git a/x2paddle/op_mapper/pytorch2paddle/prim2code.py b/x2paddle/op_mapper/pytorch2paddle/prim2code.py index 17ad50427d5a6ec0969042ba2bb094083ed1e32d..673456ce931d1329a29720915f183f67a6ad1dae 100755 --- a/x2paddle/op_mapper/pytorch2paddle/prim2code.py +++ b/x2paddle/op_mapper/pytorch2paddle/prim2code.py @@ -72,10 +72,15 @@ def prim_add_(layer, forward_func=[], layer_id=None, different_attrs=None): - line = "{} = {} + {} * {}".format(layer.outputs[0], - get_value(layer, "x", different_attrs), - layer.attrs["alpha"], - get_value(layer, "y", different_attrs)) + if abs(layer.attrs["alpha"] - 1.) < 1e-6: + line = "{} = {} + {}".format(layer.outputs[0], + get_value(layer, "x", different_attrs), + get_value(layer, "y", different_attrs)) + else: + line = "{} = {} + {} * {}".format( + layer.outputs[0], + get_value(layer, "x", different_attrs), layer.attrs["alpha"], + get_value(layer, "y", different_attrs)) forward_func.extend(gen_codes([line], indent=indent)) diff --git a/x2paddle/project_convertor/pytorch/torch2paddle/tensor.py b/x2paddle/project_convertor/pytorch/torch2paddle/tensor.py index 1c9635dba3b46325d4456d88f0a401776469785b..76e97aa7925c8a9ba88945bb6e6e588cfe7d0416 100644 --- a/x2paddle/project_convertor/pytorch/torch2paddle/tensor.py +++ b/x2paddle/project_convertor/pytorch/torch2paddle/tensor.py @@ -169,6 +169,9 @@ pd_reshape = partial(paddle.Tensor.reshape) @add_tensor_function def reshape(self, *shape): + # deal with list or tuple type + if isinstance(shape, (list, tuple)): + shape = shape[0] return pd_reshape(self, shape)