Skip to content

Commit

Permalink
fix #426 (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhreshold committed Oct 23, 2018
1 parent a411647 commit e3e8d4c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gluoncv/data/transforms/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def resize_contain(src, size, fill=0):
h, w, c = src.shape
ow, oh = size
scale_h = oh / h
scale_w = oh / w
scale_w = ow / w
scale = min(min(scale_h, scale_w), 1)
scaled_x = int(w * scale)
scaled_y = int(h * scale)
Expand Down
17 changes: 10 additions & 7 deletions tests/unittests/test_data_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,17 @@ def test_image_random_flip():
np.testing.assert_allclose(image.asnumpy()[::-1, ::-1, :], out.asnumpy())
assert(f == (True, True))

def test_image_resize_contrain():
def test_image_resize_contain():
image = mx.random.normal(shape=(240, 120, 3)).astype(np.uint8)
size = (300, 300)
out, _ = transforms.image.resize_contain(image, size)
np.testing.assert_allclose(out.shape, (300, 300, 3))
size = (100, 100)
out, _ = transforms.image.resize_contain(image, size)
np.testing.assert_allclose(out.shape, (100, 100, 3))
width = 123
height = 321
out, _ = transforms.image.resize_contain(image, (width, height))
np.testing.assert_allclose(out.shape, (height, width, 3))

width = 120
height = 20
out, _ = transforms.image.resize_contain(image, (width, height))
np.testing.assert_allclose(out.shape, (height, width, 3))

def test_image_ten_crop():
image = mx.random.normal(shape=(240, 120, 3)).astype(np.uint8)
Expand Down

0 comments on commit e3e8d4c

Please sign in to comment.