Skip to content

Commit

Permalink
[Frontend][Pytorch] add suppport for 'aten::upsample_bicubic2d' (#8648)
Browse files Browse the repository at this point in the history
* fix

* lint
  • Loading branch information
hgt312 authored Aug 5, 2021
1 parent 5b9b16c commit fe2cdf3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 7 additions & 4 deletions python/tvm/relay/frontend/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
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
Expand Down Expand Up @@ -2203,7 +2205,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])
Expand Down Expand Up @@ -2771,6 +2773,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"),
Expand Down
3 changes: 3 additions & 0 deletions tests/python/frontend/pytorch/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fe2cdf3

Please sign in to comment.