Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG_FIX] Fix resize test #6298

Merged
merged 10 commits into from
Aug 22, 2020
6 changes: 5 additions & 1 deletion python/tvm/topi/image/resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,12 @@ def resize(data, size, layout="NCHW", method="bilinear",
or [batch, in_height*scale, in_width*scale, channel]
or 5-D with shape [batch, channel-major, in_height*scale, in_width*scale, channel-minor]
"""

method = method.lower()
if ((method == "nearest_neighbor" and coordinate_transformation_mode == "align_corners") or
(method == "bilinear" and coordinate_transformation_mode != "align_corners")):
raise ValueError('Topi Resize does not support the combination of method %s ' \
'and coordinate_transformation_mode %s' %
(method, coordinate_transformation_mode))
electriclilies marked this conversation as resolved.
Show resolved Hide resolved
if layout == 'NHWC':
in_n, in_h, in_w, in_c = data.shape
if output_shape is None:
Expand Down
8 changes: 7 additions & 1 deletion tests/python/relay/dyn/test_dynamic_op_level5.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ def verify_resize(dshape, scale, method, layout):
ref_res = tvm.topi.testing.upsampling_python(x_data, (scale, scale), layout)
x = relay.var("x", relay.TensorType(dshape, "float32"))
size_var = relay.var("size", relay.TensorType((2,), "int64"))
z = relay.image.resize(x, size_var, layout, method, "align_corners")

coord_trans = "asymmetric" if method == "nearest_neighbor" else "align_corners"
z = relay.image.resize(x, size_var, layout, method,
coordinate_transformation_mode=coord_trans)

zz = run_infer_type(z)
func = relay.Function([x, size_var], z)

Expand All @@ -60,9 +64,11 @@ def verify_resize(dshape, scale, method, layout):
intrp = relay.create_executor(kind, mod=mod, ctx=ctx, target=target)
op_res = intrp.evaluate()(x_data, size)
tvm.testing.assert_allclose(op_res.asnumpy(), ref_res, rtol=1e-4, atol=1e-6)

for method in ["bilinear", "nearest_neighbor"]:
for layout in ["NCHW", "NHWC"]:
verify_resize((1, 4, 4, 4), 2, method, layout)
verify_resize((2, 8, 17, 20), 7, method, layout)

if __name__ == "__main__":
test_resize_infer_type()
Expand Down
5 changes: 4 additions & 1 deletion tests/python/relay/test_op_level5.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def verify_resize(dshape, scale, method, layout):
else:
ref_res = tvm.topi.testing.upsampling_python(x_data, (scale, scale), layout)
x = relay.var("x", relay.TensorType(dshape, "float32"))
z = relay.image.resize(x, size, layout, method, "align_corners")
coord_trans = "asymmetric" if method == "nearest_neighbor" else "align_corners"
z = relay.image.resize(x, size, layout, method,
coordinate_transformation_mode=coord_trans)
assert "size=" in z.astext()
zz = run_infer_type(z)
assert zz.checked_type == relay.TensorType(ref_res.shape, "float32")
Expand All @@ -67,6 +69,7 @@ def verify_resize(dshape, scale, method, layout):
for method in ["bilinear", "nearest_neighbor"]:
for layout in ["NHWC", "NCHW"]:
verify_resize((1, 4, 4, 4), 2, method, layout)
verify_resize((2, 8, 17, 20), 3, method, layout)

def test_resize3d_infer_type():
n, c, d, h, w = te.size_var("n"), te.size_var("c"), te.size_var("d"), te.size_var("h"), te.size_var("w")
Expand Down