-
-
Notifications
You must be signed in to change notification settings - Fork 16.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix: update dataloaders.py to fix "resize to 0" #10558
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 Hello @bobo0810, thank you for submitting a YOLOv5 🚀 PR! To allow your work to be integrated as seamlessly as possible, we advise you to:
- ✅ Verify your PR is up-to-date with
ultralytics/yolov5
master
branch. If your PR is behind you can update your code by clicking the 'Update branch' button or by runninggit pull
andgit merge master
locally. - ✅ Verify all YOLOv5 Continuous Integration (CI) checks are passing.
- ✅ Reduce changes to the absolute minimum required for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee
@bobo0810 thanks for the PR! Did you run into this error during training? What size images are you using? |
@glenn-jocher Thanks for your reply.
Look forward to your opinion~ |
@bobo0810 oh wow, that's pretty extreme. Ok yes then we need a floor at 32. I'll start working on this. |
@glenn-jocher There are many types of images that are seriously out of balance between width and height, such as resumes, blueprints, and so on. |
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
@bobo0810 I think in this case the only viable solution is to place a floor of 1 pixel on the image size. This is because this resize op should not stretch an image at all, only resize it while maintaining identical aspect ratio. 32 min stride is enforced when letterboxing later by adding grey pixels as required to reach the next multiple of 32. This will resize your image into 640x1 (before it is padded to 640x32). Inference will runs, you won't get any predictions due to the extremely narrow image size of 1 pixel, but there will be no error. im = cv2.resize(im, (math.ceil(w0 * r), math.ceil(h0 * r)), interpolation=interp) int() and math.ceil() show similar profiling times with %timeit. This will change training and val results slightly, so I'll run val.py with COCO on this branch to make sure mAP doesn't drop. |
👍 |
@bobo0810 ok YOLOv5s mAP stays the same in my test, all good. PR is merged. Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐ |
🛠️ PR Summary
Made with ❤️ by Ultralytics Actions
🌟 Summary
Improved image resizing accuracy in data loader.
📊 Key Changes
int
tomath.ceil
for calculating new image dimensions.🎯 Purpose & Impact
math.ceil
ensures that the scaling ratio is always rounded up, preventing any loss of pixels during resizing. This can be especially important for very small objects in images.