From a699c901d3b6035931c4cbf441a81337aa65513e Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 30 Nov 2019 17:38:29 -0800 Subject: [PATCH] updates --- utils/datasets.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/utils/datasets.py b/utils/datasets.py index 77c7878c..d57c385f 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -614,11 +614,15 @@ def letterbox(img, new_shape=(416, 416), color=(128, 128, 128), auto=True, scale if isinstance(new_shape, int): new_shape = (new_shape, new_shape) - r = max(new_shape) / max(shape) # ratio = new / old - ratio = r, r # width, height ratios - new_unpad = int(round(shape[1] * r)), int(round(shape[0] * r)) + # Scale ratio (new / old) + scaleup_ok = True + r = max(new_shape) / max(shape) + if not scaleup_ok: # only scale down + r = min(r, 1.0) # Compute padding + ratio = r, r # width, height ratios + new_unpad = int(round(shape[1] * r)), int(round(shape[0] * r)) dw, dh = new_shape[1] - new_unpad[0], new_shape[0] - new_unpad[1] # wh padding if auto: # minimum rectangle dw, dh = np.mod(dw, 32), np.mod(dh, 32) # wh padding