From 892c4cd4a5a99d9c824ffeb49ce512ee2c9b93e5 Mon Sep 17 00:00:00 2001 From: janus-zheng <106574221+janus-zheng@users.noreply.github.com> Date: Wed, 9 Nov 2022 22:21:43 +0800 Subject: [PATCH] AutoShape integer image-size fix (#10090) Update common.py We have a division at line 694, and then a multiplication at line 695, so it makes `y*g` not an integer. And since `shape1` will be used at line 697 to ensure the size is divisible by the `stride`, this may lead to different image size. In my experiment, my image is [640, 640], it's divisible by the default stride 32, but I found that the result is changed to [672, 672] after line 697. So the final detection result is slightly different from that directly using the `detect.py` script, which does not call the AutoShape methods. Signed-off-by: janus-zheng <106574221+janus-zheng@users.noreply.github.com> Signed-off-by: janus-zheng <106574221+janus-zheng@users.noreply.github.com> Co-authored-by: Glenn Jocher --- models/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/common.py b/models/common.py index 6347e51..64f1b93 100644 --- a/models/common.py +++ b/models/common.py @@ -692,7 +692,7 @@ class AutoShape(nn.Module): s = im.shape[:2] # HWC shape0.append(s) # image shape g = max(size) / max(s) # gain - shape1.append([y * g for y in s]) + shape1.append([int(y * g) for y in s]) ims[i] = im if im.data.contiguous else np.ascontiguousarray(im) # update shape1 = [make_divisible(x, self.stride) for x in np.array(shape1).max(0)] if self.pt else size # inf shape x = [letterbox(im, shape1, auto=False)[0] for im in ims] # pad