Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Add epsilon for tolerance level to fix flaky test random_resize_crop #15098

Merged
merged 1 commit into from
May 31, 2019
Merged
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions tests/python/unittest/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,17 +356,18 @@ def test_det_augmenters(self):
pass

@with_seed()
@unittest.skip('Flaky test. Skipping until a solution can be found. Tracked by https://github.com/apache/incubator-mxnet/issues/14718')
def test_random_size_crop(self):
# test aspect ratio within bounds
width = np.random.randint(100, 500)
height = np.random.randint(100, 500)
src = np.random.rand(height, width, 3) * 255.
ratio = (0.75, 1)
epsilon = 0.05
Copy link
Contributor

Choose a reason for hiding this comment

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

how do we decide epsilon? is 0.05 too large here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @stu1130 for the discussion offline. The randomness is caused by sqrt of area / or * ratio. Same epsilon is used in pytorch test as well. Approve this change thereby.

out, (x0, y0, new_w, new_h) = mx.image.random_size_crop(mx.nd.array(src), size=(width, height), area=0.08, ratio=ratio)
_, pts = mx.image.center_crop(mx.nd.array(src), size=(width, height))
if (x0, y0, new_w, new_h) != pts:
assert ratio[0] <= float(new_w)/new_h <= ratio[1]
assert ratio[0] - epsilon <= float(new_w)/new_h <= ratio[1] + epsilon, \
'ration of new width and height out of the bound{}/{}={}'.format(new_w, new_h, float(new_w)/new_h)


if __name__ == '__main__':
Expand Down