From 429238f7cd38c1041d6f2e57fdfbce585afab4f7 Mon Sep 17 00:00:00 2001 From: UnglvKitDe Date: Sat, 23 Jul 2022 22:34:48 +0200 Subject: [PATCH 1/6] Fix BGR->RGB Bug in albumentations https://github.com/ultralytics/yolov5/issues/8641 --- utils/augmentations.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utils/augmentations.py b/utils/augmentations.py index 3f764c06ae3b..4183cf0e89a2 100644 --- a/utils/augmentations.py +++ b/utils/augmentations.py @@ -39,8 +39,10 @@ def __init__(self): def __call__(self, im, labels, p=1.0): if self.transform and random.random() < p: + im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB) 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'])]) + im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) return im, labels From 44004d121641fd8749523770d08a33eacb5e5a9a Mon Sep 17 00:00:00 2001 From: UnglvKitDe Date: Sun, 24 Jul 2022 01:20:52 +0200 Subject: [PATCH 2/6] Change transform methode from cv2 to numpy --- utils/augmentations.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/augmentations.py b/utils/augmentations.py index 4183cf0e89a2..0c9adcb8956f 100644 --- a/utils/augmentations.py +++ b/utils/augmentations.py @@ -39,10 +39,10 @@ def __init__(self): def __call__(self, im, labels, p=1.0): if self.transform and random.random() < p: - im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB) + im = im[:,:,::-1] #BGR -> RGB 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'])]) - im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) + im = im[:,:,::-1] #RGB -> BGR return im, labels From 3b1e3ad73dbbac077a3bd12169b671fee150596c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 23 Jul 2022 23:33:49 +0000 Subject: [PATCH 3/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- utils/augmentations.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/augmentations.py b/utils/augmentations.py index 0c9adcb8956f..e49a956b71db 100644 --- a/utils/augmentations.py +++ b/utils/augmentations.py @@ -39,10 +39,10 @@ def __init__(self): def __call__(self, im, labels, p=1.0): if self.transform and random.random() < p: - im = im[:,:,::-1] #BGR -> RGB + im = im[:, :, ::-1] #BGR -> RGB 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'])]) - im = im[:,:,::-1] #RGB -> BGR + im = im[:, :, ::-1] #RGB -> BGR return im, labels From 7d1bf0b5fce3b995ce470ce424a246a079943374 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 26 Jul 2022 13:47:00 +0200 Subject: [PATCH 4/6] Simplify --- utils/augmentations.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/utils/augmentations.py b/utils/augmentations.py index e49a956b71db..b4a7580d1732 100644 --- a/utils/augmentations.py +++ b/utils/augmentations.py @@ -39,10 +39,8 @@ def __init__(self): def __call__(self, im, labels, p=1.0): if self.transform and random.random() < p: - im = im[:, :, ::-1] #BGR -> RGB - 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'])]) - im = im[:, :, ::-1] #RGB -> BGR + new = self.transform(image=im[..., ::-1], bboxes=labels[:, 1:], class_labels=labels[:, 0]) # transformed + im, labels = new['image'][..., ::-1], np.array([[c, *b] for c, b in zip(new['class_labels'], new['bboxes'])]) return im, labels From 797129070ac408ca3187fdc040e1ab455f1c4631 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 Jul 2022 11:47:46 +0000 Subject: [PATCH 5/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- utils/augmentations.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/augmentations.py b/utils/augmentations.py index b4a7580d1732..62810c9a3f0a 100644 --- a/utils/augmentations.py +++ b/utils/augmentations.py @@ -40,7 +40,8 @@ def __init__(self): def __call__(self, im, labels, p=1.0): if self.transform and random.random() < p: new = self.transform(image=im[..., ::-1], bboxes=labels[:, 1:], class_labels=labels[:, 0]) # transformed - im, labels = new['image'][..., ::-1], np.array([[c, *b] for c, b in zip(new['class_labels'], new['bboxes'])]) + im, labels = new['image'][..., ::-1], np.array([[c, *b] + for c, b in zip(new['class_labels'], new['bboxes'])]) return im, labels From 253beec1e6bbc4942064269bfe24c837661845b4 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 26 Jul 2022 13:51:00 +0200 Subject: [PATCH 6/6] Update augmentations.py --- utils/augmentations.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/augmentations.py b/utils/augmentations.py index 62810c9a3f0a..97506ae25123 100644 --- a/utils/augmentations.py +++ b/utils/augmentations.py @@ -40,8 +40,8 @@ def __init__(self): def __call__(self, im, labels, p=1.0): if self.transform and random.random() < p: new = self.transform(image=im[..., ::-1], bboxes=labels[:, 1:], class_labels=labels[:, 0]) # transformed - im, labels = new['image'][..., ::-1], np.array([[c, *b] - for c, b in zip(new['class_labels'], new['bboxes'])]) + 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