Fix BGR->RGB Bug in albumentations #8641 (#8695)

* Fix BGR->RGB Bug in albumentations https://github.com/ultralytics/yolov5/issues/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>
pull/8725/head
UnglvKitDe 2022-07-26 13:52:56 +02:00 committed by GitHub
parent b367860196
commit 2e1291fdce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -39,8 +39,9 @@ class Albumentations:
def __call__(self, im, labels, p=1.0):
if self.transform and random.random() < p:
new = self.transform(image=im, bboxes=labels[:, 1:], class_labels=labels[:, 0]) # transformed
im, labels = new['image'], np.array([[c, *b] for c, b in zip(new['class_labels'], new['bboxes'])])
new = self.transform(image=im[..., ::-1], bboxes=labels[:, 1:], class_labels=labels[:, 0]) # transformed
im = new['image'][..., ::-1] # RGB to BGR
labels = np.array([[c, *b] for c, b in zip(new['class_labels'], new['bboxes'])])
return im, labels