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

Fix RGB Albumentations order #8747

Closed
wants to merge 2 commits into from
Closed

Conversation

glenn-jocher
Copy link
Member

@glenn-jocher glenn-jocher commented Jul 27, 2022

Second attempt at resolving RGB Albmentations order issue #8695.

First PR fix #8695 failed and reverted.

πŸ› οΈ PR Summary

Made with ❀️ by Ultralytics Actions

🌟 Summary

Improved color handling in image augmentations and loading by ensuring consistent RGB color space usage.

πŸ“Š Key Changes

  • Changed cv2.COLOR_BGR2HSV to cv2.COLOR_RGB2HSV in augment_hsv() to start with RGB images for HSV conversion.
  • Updated cv2.COLOR_HSV2BGR to cv2.COLOR_HSV2RGB after HSV operations to maintain images in RGB format.
  • Removed reverse channel ordering (BGR to RGB conversion) from transpose operation in __getitem__() in dataloaders.py.
  • Added explicit RGB format notation in load_image() and cache_images_to_disk to indicate that images are kept in RGB.

🎯 Purpose & Impact

  • Ensures image data is consistently in RGB format throughout processing, which aligns with commonly used image formats in machine learning and reduces confusion.
  • These changes should make the codebase more intuitive and reduce potential errors related to color space mismanagement, resulting in a smoother development and training experience for users working with the YOLOv5 code. πŸ—οΈπŸŒˆ

@glenn-jocher
Copy link
Member Author

Seems like it's working. The only thing I'm worried about is non-contiguous images being passed around the dataloader. I'll check to see if they're contiguous

Copy link
Contributor

@UnglvKitDe UnglvKitDe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good :)

utils/dataloaders.py Show resolved Hide resolved
@UnglvKitDe
Copy link
Contributor

Seems like it's working. The only thing I'm worried about is non-contiguous images being passed around the dataloader. I'll check to see if they're contiguous

@glenn-jocher But what does that have to do with the changes here? Or do you mean they could become noncontinous because of the changes?

@glenn-jocher
Copy link
Member Author

glenn-jocher commented Jul 29, 2022

@UnglvKitDe ops on non-contiguous arrays will still run but they are no longer optimized and the operations may be much slower, i.e.:

import cv2
import numpy

im_bgr = cv2.imread('data/images/bus.jpg')
im_rgb1 = im_bgr[...,::-1]
im_rgb2 = cv2.cvtColor(im_bgr, cv2.COLOR_BGR2RGB)

print(im_bgr.data.contiguous)  # True
print(im_rgb1.data.contiguous)  # False
print(im_rgb2.data.contiguous)  # True

@UnglvKitDe
Copy link
Contributor

@UnglvKitDe ops on non-contiguous arrays will still run but they are no longer optimized and the operations may be much slower, i.e.:

import cv2
import numpy

im_bgr = cv2.imread('data/images/bus.jpg')
im_rgb1 = im_bgr[...,::-1]
im_rgb2 = cv2.cvtColor(im_bgr, cv2.COLOR_BGR2RGB)

print(im_bgr.data.contiguous)  # True
print(im_rgb1.data.contiguous)  # False
print(im_rgb2.data.contiguous)  # True

Mh ok, thats a good point.

@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions YOLOv5 πŸš€ and Vision AI ⭐.

@github-actions github-actions bot added the Stale label Mar 22, 2023
@github-actions github-actions bot removed the Stale label Apr 10, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2023

πŸ‘‹ Hello there! We wanted to let you know that we've decided to close this pull request due to inactivity. We appreciate the effort you put into contributing to our project, but unfortunately, not all contributions are suitable or aligned with our product roadmap.

We hope you understand our decision, and please don't let it discourage you from contributing to open source projects in the future. We value all of our community members and their contributions, and we encourage you to keep exploring new projects and ways to get involved.

For additional resources and information, please see the links below:

Thank you for your contributions to YOLO πŸš€ and Vision AI ⭐

@github-actions github-actions bot added the Stale label Oct 3, 2023
@github-actions github-actions bot closed this Nov 3, 2023
@glenn-jocher
Copy link
Member Author

@UnglvKitDe yes, it's important to ensure that the image arrays remain contiguous for performance reasons. The changes in the PR should not affect the contiguity of the arrays, but it's always good to verify that such issues don't arise with modifications to image handling. If you encounter any performance issues or have further questions, feel free to reach out. Thanks for your contribution! πŸš€

@glenn-jocher glenn-jocher deleted the fix/rgb_albumentations branch June 8, 2024 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants