From cf7c1c9ca315d942ed48a2eb2057384219c6a25a Mon Sep 17 00:00:00 2001 From: hgt312 Date: Wed, 4 Aug 2021 19:38:11 +0800 Subject: [PATCH 1/2] fix --- python/tvm/relay/frontend/pytorch.py | 9 +++++---- tests/python/frontend/pytorch/test_forward.py | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index 33cb83b883bc..4e16ffd75ab4 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -1799,7 +1799,7 @@ def get_upsample_out_size(self, inputs, method): else: out_size.append(size) else: - scale_index = 3 if method == "linear" else 2 + scale_index = 3 if method != "nearest_neighbor" else 2 scales = inputs[scale_index] assert scales is not None, "neither out size nor scale provided" assert isinstance(scales, list) @@ -1814,7 +1814,7 @@ def upsample(inputs, input_types): data = inputs[0] out_size = self.get_upsample_out_size(inputs, method) - if len(inputs) > 2 and method == "linear": + if len(inputs) > 2 and method != "nearest_neighbor": align_corners = inputs[2] else: align_corners = False @@ -1827,7 +1827,7 @@ def upsample(inputs, input_types): coord_trans = "half_pixel" def func(x): - return _op.image.resize2d(x, out_size, "NCHW", method, coord_trans) + return _op.image.resize2d(x, out_size, "NCHW", method, coord_trans, cubic_alpha=-0.75) if self.is_quantized_tensor(data): # input qparams are manually appended by us @@ -2203,7 +2203,7 @@ def interpolate(self, inputs, input_types): else: coord_trans = "half_pixel" - return _op.image.resize2d(data, out_size, "NCHW", method, coord_trans) + return _op.image.resize2d(data, out_size, "NCHW", method, coord_trans, cubic_alpha=-0.75) def numel(self, inputs, input_types): return _op.ndarray_size(inputs[0]) @@ -2771,6 +2771,7 @@ def create_convert_map(self): "aten::clamp_": self.clamp, "aten::detach": self.identity, "aten::upsample_bilinear2d": self.make_upsample("linear"), + "aten::upsample_bicubic2d": self.make_upsample("cubic"), "aten::upsample_nearest2d": self.make_upsample("nearest_neighbor"), "aten::upsample_trilinear3d": self.make_upsample3d("linear"), "aten::upsample_nearest3d": self.make_upsample3d("nearest_neighbor"), diff --git a/tests/python/frontend/pytorch/test_forward.py b/tests/python/frontend/pytorch/test_forward.py index f76ea9a5d324..fc061be5b10a 100644 --- a/tests/python/frontend/pytorch/test_forward.py +++ b/tests/python/frontend/pytorch/test_forward.py @@ -1756,6 +1756,9 @@ def forward(self, x): verify_model(Upsample(size=(64, 64), mode="bilinear", align_corners=True), inp) verify_model(Upsample(scale=2, mode="bilinear", align_corners=True), inp) verify_model(Upsample(size=(50, 50), mode="bilinear", align_corners=True), inp) + verify_model(Upsample(size=(64, 64), mode="bicubic", align_corners=True), inp) + verify_model(Upsample(scale=2, mode="bicubic", align_corners=True), inp) + verify_model(Upsample(size=(50, 50), mode="bicubic", align_corners=True), inp) @tvm.testing.uses_gpu From 30b37d09f8100640bbde93c8ee810fb3eeb327e1 Mon Sep 17 00:00:00 2001 From: hgt312 Date: Wed, 4 Aug 2021 19:44:50 +0800 Subject: [PATCH 2/2] lint --- python/tvm/relay/frontend/pytorch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index 4e16ffd75ab4..4a8570ea5ae8 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -1827,7 +1827,9 @@ def upsample(inputs, input_types): coord_trans = "half_pixel" def func(x): - return _op.image.resize2d(x, out_size, "NCHW", method, coord_trans, cubic_alpha=-0.75) + return _op.image.resize2d( + x, out_size, "NCHW", method, coord_trans, cubic_alpha=-0.75 + ) if self.is_quantized_tensor(data): # input qparams are manually appended by us