diff --git a/chainercv/transforms/image/scale.py b/chainercv/transforms/image/scale.py index 32b1c13a7c..84e91ca25d 100644 --- a/chainercv/transforms/image/scale.py +++ b/chainercv/transforms/image/scale.py @@ -27,9 +27,9 @@ def scale(img, size, fit_short=True): _, H, W = img.shape # If resizing is not necessary, return the input as is. - if fit_short and (H <= W and H == size) or (W <= H and W == size): + if fit_short and ((H <= W and H == size) or (W <= H and W == size)): return img - if not fit_short and (H >= W and H == size) or (W >= H and W == size): + if not fit_short and ((H >= W and H == size) or (W >= H and W == size)): return img if fit_short: diff --git a/tests/transforms_tests/image_tests/test_scale.py b/tests/transforms_tests/image_tests/test_scale.py index c0c9e3e3cb..3f160e3db4 100644 --- a/tests/transforms_tests/image_tests/test_scale.py +++ b/tests/transforms_tests/image_tests/test_scale.py @@ -11,10 +11,14 @@ 'fit_short': True, 'out_shape': (3, 12, 8)}, {'in_shape': (3, 16, 24), 'size': 8, 'fit_short': True, 'out_shape': (3, 8, 12)}, + {'in_shape': (3, 16, 24), 'size': 24, + 'fit_short': True, 'out_shape': (3, 24, 36)}, {'in_shape': (3, 24, 16), 'size': 36, 'fit_short': False, 'out_shape': (3, 36, 24)}, {'in_shape': (3, 16, 24), 'size': 36, 'fit_short': False, 'out_shape': (3, 24, 36)}, + {'in_shape': (3, 24, 12), 'size': 12, + 'fit_short': False, 'out_shape': (3, 12, 6)}, # grayscale {'in_shape': (1, 16, 24), 'size': 8, 'fit_short': True, 'out_shape': (1, 8, 12)},