-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
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
Albumentations-Pipeline is applied to BGR not to RGB #8641
Comments
YOLOv5 uses the following augmentation transforms Line 28 in 92e47b8
AFAIK, all other transforms except CLAHE are channel order independent. |
@seonho According to the current state YOLOv5 also uses Gray. There it depends on the implementation of cv2.cvtCOLOR() how the RGB image is transformed to a Gray image (I couldn't find the OpenCV implementation). But either way, it is confusing if you want to adjust e.g. the default pipline for your dataset. |
@UnglvKitDe Yes, I missed So, at least two (ToGray, CLAHE) transforms are channel order dependent. |
@UnglvKitDe yes you are correct, there is an inconsistency there is Albumentations is used. The best solution I can think of is to immediately convert to RGB after cv2 imread (and update where required like augment_hsv()). Then we can safely assume RGB-order images throughout all dataloaders. I think this might be slightly slower than the current implementation which reverses BGR-RGB in the first dimension (CHW) rather than the last (HWC), resulting in a faster BGR-RGB conversion. I'll add a TODO here so I don't forget. TODO: Fix bug that Albumentations inputs BGR images but expects RGB images. |
@glenn-jocher I have pushed a first idea. |
@UnglvKitDe thanks! I will take a look at the PR. For reference some BGR to RGB speeds: import numpy as np
import cv2
import time
im = np.random.rand(640,640,3).astype(np.uint8)
t = time.time()
for _ in range(10000):
x = im[...,::-1]
print(time.time() - t)
t = time.time()
for _ in range(10000):
np.flip(im,2)
print(time.time() - t)
t = time.time()
for _ in range(10000):
cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
print(time.time() - t) |
Faster crops Following #8641 (comment)
@glenn-jocher Oh thats a good point. I thought opencv do something like that. But it looks very slow. Thx! |
* Fix BGR->RGB Bug in albumentations #8641 * Change transform methode from cv2 to numpy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Simplify * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update augmentations.py Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Faster crops Following ultralytics#8641 (comment)
* Fix BGR->RGB Bug in albumentations ultralytics#8641 * Change transform methode from cv2 to numpy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Simplify * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update augmentations.py Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
…tics#8727) Revert "Fix BGR->RGB Bug in albumentations ultralytics#8641 (ultralytics#8695)" This reverts commit 2e1291f.
@UnglvKitDe you're welcome! Thank you for your understanding. Let me know if you have any questions or need further assistance with the PR. |
Search before asking
YOLOv5 Component
No response
Bug
As written here in step 3, Albumentations internally uses the RGB format and not the BGR format of opencv. However, the data is currently passed internally as BGR:
yolov5/utils/dataloaders.py
Lines 626 to 628 in 92e47b8
yolov5/utils/dataloaders.py
Line 654 in 92e47b8
Or am I missing something?
Environment
YOLOv5 torch 1.11 (cuda 11.3) and 1.12 (cuda 11.6)
Minimal Reproducible Example
No response
Additional
No response
Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: