Skip to content

Commit

Permalink
Copy-Paste zero value fix (#10152)
Browse files Browse the repository at this point in the history
* Copy-Paste zero value fix

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>

* Update augmentations.py

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
  • Loading branch information
glenn-jocher committed Nov 14, 2022
1 parent f33718f commit abbfd69
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions utils/augmentations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 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
Expand Down

0 comments on commit abbfd69

Please sign in to comment.