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

Use torch.testing.assert_close in test_anchor_utils.py #3880

Merged
merged 25 commits into from
May 21, 2021
Merged
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c4fc01b
adopt `torch.testing.assert_close` in test suite
pmeier May 20, 2021
bfbe19b
revert some changes
pmeier May 20, 2021
09f86f4
add todo
pmeier May 20, 2021
86402f0
flake8
pmeier May 20, 2021
48d32e6
Hopefully fixed test_functional_tensor
NicolasHug May 20, 2021
15b50e3
hopefully fixed test_ops
NicolasHug May 20, 2021
a54880f
Merge branch 'master' of github.com:pytorch/vision into assert-close
NicolasHug May 20, 2021
61874ac
Fix test_utils
NicolasHug May 20, 2021
30f20a3
revert unwanted changes to test_image
NicolasHug May 20, 2021
3a29ae3
maybe fixed test_transforms
NicolasHug May 20, 2021
d6d73d0
Merge branch 'master' into assert-close
NicolasHug May 20, 2021
863f144
fix test_datasets_video_utils
pmeier May 21, 2021
c8a5afa
fix test_transforms
pmeier May 21, 2021
e697e88
Merge branch 'master' into assert-close
pmeier May 21, 2021
93614f0
flake8
pmeier May 21, 2021
11caf01
Merge branch 'master' of github.com:pytorch/vision into assert-close
NicolasHug May 21, 2021
d7fde8c
Merge branch 'assert-close' of github.com:pmeier/vision into assert-c…
NicolasHug May 21, 2021
0b237c7
use cu102 see if the nightlies are actual nightlies?
NicolasHug May 21, 2021
c2ace86
obviously forgot to call regenerate.py
NicolasHug May 21, 2021
d78226a
not as obvious, reverting
NicolasHug May 21, 2021
bb543a7
Merge branch 'master' into assert-close
NicolasHug May 21, 2021
7507a0c
Merge branch 'master' into assert-close
NicolasHug May 21, 2021
a4726cb
revert everything but anchor_utils
NicolasHug May 21, 2021
c071048
Merge branch 'master' into assert_close_anchor
NicolasHug May 21, 2021
4cd13a7
Merge branch 'master' into assert_close_anchor
NicolasHug May 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions test/test_models_detection_anchor_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import torch
from common_utils import TestCase
from _assert_utils import assert_equal
from torchvision.models.detection.anchor_utils import AnchorGenerator, DefaultBoxGenerator
from torchvision.models.detection.image_list import ImageList

Expand Down Expand Up @@ -62,8 +63,8 @@ def test_anchor_generator(self):
self.assertEqual(len(anchors), 2)
self.assertEqual(tuple(anchors[0].shape), (9, 4))
self.assertEqual(tuple(anchors[1].shape), (9, 4))
self.assertEqual(anchors[0], anchors_output)
self.assertEqual(anchors[1], anchors_output)
assert_equal(anchors[0], anchors_output)
assert_equal(anchors[1], anchors_output)

def test_defaultbox_generator(self):
images = torch.zeros(2, 3, 15, 15)
Expand All @@ -85,5 +86,5 @@ def test_defaultbox_generator(self):
self.assertEqual(len(dboxes), 2)
self.assertEqual(tuple(dboxes[0].shape), (4, 4))
self.assertEqual(tuple(dboxes[1].shape), (4, 4))
self.assertTrue(dboxes[0].allclose(dboxes_output))
self.assertTrue(dboxes[1].allclose(dboxes_output))
torch.testing.assert_close(dboxes[0], dboxes_output, rtol=1e-5, atol=1e-8)
torch.testing.assert_close(dboxes[1], dboxes_output, rtol=1e-5, atol=1e-8)
Comment on lines +89 to +90
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it's a bit of a shame IMHO that we're forced to specify atol as well. The default for atol is 1e-5 and

        torch.testing.assert_close(dboxes[0], dboxes_output, rtol=1e-5, atol=1e-5)
        torch.testing.assert_close(dboxes[1], dboxes_output, rtol=1e-5, atol=1e-5)

passes just fine, so ideally we could just write

        torch.testing.assert_close(dboxes[0], dboxes_output, rtol=1e-5)
        torch.testing.assert_close(dboxes[1], dboxes_output, rtol=1e-5)