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

Resize produces incorrect results #6237

Closed
electriclilies opened this issue Aug 8, 2020 · 3 comments
Closed

Resize produces incorrect results #6237

electriclilies opened this issue Aug 8, 2020 · 3 comments

Comments

@electriclilies
Copy link
Contributor

electriclilies commented Aug 8, 2020

The relay reshape function produces incorrect results. For scale factors other than 2, the output of relay.resize does not match the testing function.

The test I changed:

--- a/tests/python/relay/test_op_level5.py
+++ b/tests/python/relay/test_op_level5.py
@@ -66,7 +66,7 @@ def test_resize():
tvm.testing.assert_allclose(op_res.asnumpy(), ref_res, rtol=1e-4, atol=1e-6)
for method in ["bilinear", "nearest_neighbor"]:
for layout in ["NHWC", "NCHW"]:
- verify_resize((1, 4, 4, 4), 2, method, layout)
+ verify_resize((1, 4, 4, 4), 7, method, layout)

In this particular case, we get this error:

   AssertionError: 
   Not equal to tolerance rtol=0.0001, atol=1e-06
   
   Mismatched elements: 832 / 3136 (26.5%)
   Max absolute difference: 0.8489792
   Max relative difference: 711.5619
    x: array([[[[0.507647, 0.792792, 0.245963, 0.439271],
            [0.507647, 0.792792, 0.245963, 0.439271],
            [0.507647, 0.792792, 0.245963, 0.439271],...
    y: array([[[[0.507647, 0.792792, 0.245963, 0.439271],
            [0.507647, 0.792792, 0.245963, 0.439271],
            [0.507647, 0.792792, 0.245963, 0.439271],...

cc @mbrookhart

@mbrookhart
Copy link
Contributor

mbrookhart commented Aug 17, 2020

It looks like it's failing with NHWC nearest_neighbor. Looking at git blame, it seems @masahi worked on the test utility and @yongwww worked on the topi op. Could one or both of you take a look at this?

@masahi
Copy link
Member

masahi commented Aug 18, 2020

Using align_corner option with nearest is a mistake: https://github.com/apache/incubator-tvm/blob/master/tests/python/relay/test_op_level5.py#L56

For nearest, I think the coordinate transform option should always be assymetric. The following should fix the test. The same fix should be applied to the dynamic one added in #6198.

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

@electriclilies A PR welcome, or you can add the fix above to one of your on going PRs.

@electriclilies
Copy link
Contributor Author

Proposed fix is in #6298

@masahi masahi closed this as completed Aug 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants