Nothing Special   »   [go: up one dir, main page]

Skip to content
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

Merged
merged 3 commits into from
Dec 22, 2022
Merged

Bugfix: update dataloaders.py to fix "resize to 0" #10558

merged 3 commits into from
Dec 22, 2022

Conversation

bobo0810
Copy link
Contributor
@bobo0810 bobo0810 commented Dec 22, 2022
  • Problem: When the ratio of width to height of the image is too large, the short side will scale to 0, causing an error.
  • Solution: Set minimum lower bound for short side.

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Improved image resizing accuracy in data loader.

📊 Key Changes

  • Changed the image resizing function from int to math.ceil for calculating new image dimensions.

🎯 Purpose & Impact

  • Enhanced Precision: Using 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.
  • Image Quality: This may improve the preservation of image details when the image is scaled up, leading to potentially better object detection performance.
  • Downstream Effects: The change could affect how models trained on resized images perform, although the impact is likely to be quite minor for most use cases.

Copy link
Contributor
@github-actions github-actions bot left a 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 running git pull and git 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

@glenn-jocher
Copy link
Member

@bobo0810 thanks for the PR! Did you run into this error during training? What size images are you using?

@bobo0810
Copy link
Contributor Author
bobo0810 commented Dec 22, 2022

@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.

  • I got an error doing the following python val.py --task "test", image size 32738 x 23.
  • I think we should set a lower bound on scaling for code robustness.

Look forward to your opinion~

@glenn-jocher
Copy link
Member

@bobo0810 oh wow, that's pretty extreme. Ok yes then we need a floor at 32. I'll start working on this.

@bobo0810
Copy link
Contributor Author
bobo0810 commented Dec 22, 2022

@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.
Again, thanks for your work~

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
@glenn-jocher
Copy link
Member
glenn-jocher commented Dec 22, 2022

@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
Copy link
Contributor Author

👍

@glenn-jocher glenn-jocher merged commit 2370a55 into ultralytics:master Dec 22, 2022
@glenn-jocher
Copy link
Member

@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 ⭐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants