update copy-paste

exp-a
Laughing-q 8 months ago
parent ded2f84b97
commit 5e56d580cb
  1. 16
      ultralytics/data/augment.py
  2. 4
      ultralytics/data/dataset.py

@ -810,6 +810,22 @@ class CopyPaste:
i = cv2.flip(im_new, 1).astype(bool)
im[i] = result[i]
im_new = np.zeros(im.shape, np.uint8)
ins_flip = deepcopy(instances)
ins_flip.flipud(w)
ioa = bbox_ioa(ins_flip.bboxes, instances.bboxes) # intersection over area, (N, M)
indexes = np.nonzero((ioa < 0.30).all(1))[0] # (N, )
n = len(indexes)
for j in random.sample(list(indexes), k=round(self.p * n)):
cls = np.concatenate((cls, cls[[j]]), axis=0)
instances = Instances.concatenate((instances, ins_flip[[j]]), axis=0)
cv2.drawContours(im_new, instances.segments[[j]].astype(np.int32), -1, (1, 1, 1), cv2.FILLED)
result = cv2.flip(im, 0) # augment segments (flip left-right)
i = cv2.flip(im_new, 0).astype(bool)
im[i] = result[i]
labels["img"] = im
labels["cls"] = cls
labels["instances"] = instances

@ -175,8 +175,8 @@ class YOLODataset(BaseDataset):
def close_mosaic(self, hyp):
"""Sets mosaic, copy_paste and mixup options to 0.0 and builds transformations."""
hyp.mosaic = 0.0 # set mosaic ratio=0.0
# hyp.copy_paste = 0.0 # keep the same behavior as previous v8 close-mosaic
# hyp.mixup = 0.0 # keep the same behavior as previous v8 close-mosaic
hyp.copy_paste = 0.0 # keep the same behavior as previous v8 close-mosaic
hyp.mixup = 0.0 # keep the same behavior as previous v8 close-mosaic
self.transforms = self.build_transforms(hyp)
def update_labels_info(self, label):

Loading…
Cancel
Save