Unverified Commit 3b8a1403 authored by Francisco Massa's avatar Francisco Massa Committed by GitHub
Browse files

Fix TypeError due to float instead of int in RandomResizedCrop.get_params (#1036)

parent f6262182
...@@ -147,10 +147,14 @@ class Tester(unittest.TestCase): ...@@ -147,10 +147,14 @@ class Tester(unittest.TestCase):
aspect_min = max(round(random.random(), 2), epsilon) aspect_min = max(round(random.random(), 2), epsilon)
aspect_ratio_range = (aspect_min, aspect_min + round(random.random(), 2)) aspect_ratio_range = (aspect_min, aspect_min + round(random.random(), 2))
randresizecrop = transforms.RandomResizedCrop(size, scale_range, aspect_ratio_range) randresizecrop = transforms.RandomResizedCrop(size, scale_range, aspect_ratio_range)
_, _, h, w = randresizecrop.get_params(img, scale_range, aspect_ratio_range) i, j, h, w = randresizecrop.get_params(img, scale_range, aspect_ratio_range)
aspect_ratio_obtained = w / h aspect_ratio_obtained = w / h
assert (min(aspect_ratio_range) - epsilon <= aspect_ratio_obtained <= max(aspect_ratio_range) + epsilon or assert (min(aspect_ratio_range) - epsilon <= aspect_ratio_obtained <= max(aspect_ratio_range) + epsilon or
aspect_ratio_obtained == 1.0) aspect_ratio_obtained == 1.0)
assert isinstance(i, int)
assert isinstance(j, int)
assert isinstance(h, int)
assert isinstance(w, int)
def test_randomperspective(self): def test_randomperspective(self):
for _ in range(10): for _ in range(10):
......
...@@ -652,10 +652,10 @@ class RandomResizedCrop(object): ...@@ -652,10 +652,10 @@ class RandomResizedCrop(object):
in_ratio = img.size[0] / img.size[1] in_ratio = img.size[0] / img.size[1]
if (in_ratio < min(ratio)): if (in_ratio < min(ratio)):
w = img.size[0] w = img.size[0]
h = w / min(ratio) h = int(round(w / min(ratio)))
elif (in_ratio > max(ratio)): elif (in_ratio > max(ratio)):
h = img.size[1] h = img.size[1]
w = h * max(ratio) w = int(round(h * max(ratio)))
else: # whole image else: # whole image
w = img.size[0] w = img.size[0]
h = img.size[1] h = img.size[1]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment