Skip to content

Commit

Permalink
AutoShape integer image-size fix (#10090)
Browse files Browse the repository at this point in the history
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 <[email protected]>

Signed-off-by: janus-zheng <[email protected]>
Co-authored-by: Glenn Jocher <[email protected]>
  • Loading branch information
janus-zheng and glenn-jocher authored Nov 9, 2022
1 parent 86decb3 commit 892c4cd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ def forward(self, ims, size=640, augment=False, profile=False):
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
Expand Down

0 comments on commit 892c4cd

Please sign in to comment.