From 1234baa0d4dcfca808e450e2c5c4617f0c9d8993 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 14 Nov 2022 14:51:48 +0100 Subject: [PATCH 1/2] Copy-Paste zero value fix Signed-off-by: Glenn Jocher --- utils/augmentations.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/utils/augmentations.py b/utils/augmentations.py index 7c8e0bcdede6..6acf24267d55 100644 --- a/utils/augmentations.py +++ b/utils/augmentations.py @@ -250,12 +250,10 @@ def copy_paste(im, labels, segments, p=0.5): if (ioa < 0.30).all(): # allow 30% obscuration of existing labels labels = np.concatenate((labels, [[l[0], *box]]), 0) segments.append(np.concatenate((w - s[:, 0:1], s[:, 1:2]), 1)) - cv2.drawContours(im_new, [segments[j].astype(np.int32)], -1, (255, 255, 255), cv2.FILLED) + cv2.drawContours(im_new, [segments[j].astype(np.int32)], -1, (1, 1, 1), cv2.FILLED) - result = cv2.bitwise_and(src1=im, src2=im_new) - result = cv2.flip(result, 1) # augment segments (flip left-right) - i = result > 0 # pixels to replace - # i[:, :] = result.max(2).reshape(h, w, 1) # act over ch + result = np.flip(im, 1) # augment segments (flip left-right) + i = np.flip(im_new.astype(bool), 1) im[i] = result[i] # cv2.imwrite('debug.jpg', im) # debug return im, labels, segments From 31492047b5214f4d8b99736e336e378b7da417b8 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 14 Nov 2022 18:32:12 +0100 Subject: [PATCH 2/2] Update augmentations.py Signed-off-by: Glenn Jocher --- utils/augmentations.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/augmentations.py b/utils/augmentations.py index 6acf24267d55..1eae5db8f816 100644 --- a/utils/augmentations.py +++ b/utils/augmentations.py @@ -252,8 +252,8 @@ def copy_paste(im, labels, segments, p=0.5): segments.append(np.concatenate((w - s[:, 0:1], s[:, 1:2]), 1)) cv2.drawContours(im_new, [segments[j].astype(np.int32)], -1, (1, 1, 1), cv2.FILLED) - result = np.flip(im, 1) # augment segments (flip left-right) - i = np.flip(im_new.astype(bool), 1) + result = cv2.flip(im, 1) # augment segments (flip left-right) + i = cv2.flip(im_new, 1).astype(bool) im[i] = result[i] # cv2.imwrite('debug.jpg', im) # debug return im, labels, segments