From 83dc7b023a7e113e17d6470112227c434036dc64 Mon Sep 17 00:00:00 2001 From: knotgrass <40136779+knotgrass@users.noreply.github.com> Date: Sat, 21 Sep 2024 21:52:07 +0700 Subject: [PATCH 1/2] add brg augmentation --- data/hyps/hyp.scratch-high.yaml | 1 + utils/dataloaders.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/data/hyps/hyp.scratch-high.yaml b/data/hyps/hyp.scratch-high.yaml index fdb2c3788..19ce9bb39 100644 --- a/data/hyps/hyp.scratch-high.yaml +++ b/data/hyps/hyp.scratch-high.yaml @@ -28,3 +28,4 @@ fliplr: 0.5 # image flip left-right (probability) mosaic: 1.0 # image mosaic (probability) mixup: 0.15 # image mixup (probability) copy_paste: 0.3 # segment copy-paste (probability) +bgr: 0.5 # bgr -> rgb (probability) diff --git a/utils/dataloaders.py b/utils/dataloaders.py index 776042999..42146897b 100644 --- a/utils/dataloaders.py +++ b/utils/dataloaders.py @@ -706,6 +706,10 @@ def __getitem__(self, index): if nl: labels[:, 1] = 1 - labels[:, 1] + # bgr + if random.random() < hyp['bgr']: + img = img[..., ::-1] + # Cutouts # labels = cutout(img, labels, p=0.5) # nl = len(labels) # update after cutout From ba670d0ad48532f256862b7f5110d4f715b99a53 Mon Sep 17 00:00:00 2001 From: knotgrass <40136779+knotgrass@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:54:07 +0700 Subject: [PATCH 2/2] add gray aug --- data/hyps/hyp.scratch-high.yaml | 4 +++- utils/dataloaders.py | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/data/hyps/hyp.scratch-high.yaml b/data/hyps/hyp.scratch-high.yaml index 19ce9bb39..688efd755 100644 --- a/data/hyps/hyp.scratch-high.yaml +++ b/data/hyps/hyp.scratch-high.yaml @@ -28,4 +28,6 @@ fliplr: 0.5 # image flip left-right (probability) mosaic: 1.0 # image mosaic (probability) mixup: 0.15 # image mixup (probability) copy_paste: 0.3 # segment copy-paste (probability) -bgr: 0.5 # bgr -> rgb (probability) +# assert bgr + gray + origin = 1 +bgr: 0.333 # bgr -> rgb (probability) +gray: 0.333 # brg -> gray (probability) diff --git a/utils/dataloaders.py b/utils/dataloaders.py index 42146897b..64dadd110 100644 --- a/utils/dataloaders.py +++ b/utils/dataloaders.py @@ -706,9 +706,14 @@ def __getitem__(self, index): if nl: labels[:, 1] = 1 - labels[:, 1] - # bgr - if random.random() < hyp['bgr']: + # gray and brg + _p = random.random() + if _p < hyp['bgr']: img = img[..., ::-1] + elif _p < hyp['bgr'] + hyp['gray']: + img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) + img = np.stack((img, img, img), axis=-1) + del _p # Cutouts # labels = cutout(img, labels, p=0.5)