Skip to content

Commit

Permalink
Experiment with mosaic aug only ultralytics#17.5
Browse files Browse the repository at this point in the history
  • Loading branch information
manole-alexandru committed Apr 18, 2023
1 parent e40d511 commit c0954d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio
ema.update_attr(model, include=['yaml', 'nc', 'hyp', 'names', 'stride', 'class_weights'])
final_epoch = (epoch + 1 == epochs) or stopper.possible_stop
if not noval or final_epoch: # Calculate mAP
'''
# Right now this does not work with Mosaic aug
results_train, maps_train, _ = validate.run(data_dict,
batch_size=batch_size // WORLD_SIZE * 2,
imgsz=imgsz,
Expand All @@ -402,7 +404,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio
plots=False,
callbacks=callbacks,
compute_loss=compute_loss)

'''
results, maps, _ = validate.run(data_dict,
batch_size=batch_size // WORLD_SIZE * 2,
imgsz=imgsz,
Expand Down Expand Up @@ -550,7 +552,7 @@ def parse_opt(known=False):


def main(opt, callbacks=Callbacks()):
print('\n---------- VERSION:', '#0017', '----------\n')
print('\n---------- VERSION:', '#0017.5', '----------\n')
# Checks
if RANK in {-1, 0}:
print_args(vars(opt))
Expand Down
5 changes: 5 additions & 0 deletions utils/dataloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,12 +696,14 @@ def __getitem__(self, index):
seg, _, _ = random_perspective(seg, labels, degrees=hyp['degrees'], translate=hyp['translate'], scale=hyp['scale'],
shear=hyp['shear'], perspective=hyp['perspective'], random_parameters=random_parameters,
border_value=(0, 0, 0))
'''
if index < 50:
cv2.imwrite('runs/image' + str(index) + '.jpg', img)
cv2.imwrite('runs/mask' + str(index) + '.png', seg)
h, w = seg.shape[0], seg.shape[1]
resized = cv2.resize(seg, (w * 2, h * 2), interpolation=cv2.INTER_AREA)
cv2.imwrite('runs/maskr' + str(index) + '.png', resized)
'''

nl = len(labels) # number of labels
if nl:
Expand Down Expand Up @@ -834,6 +836,8 @@ def load_mosaic(self, index):

# Augment
img4, labels4, segments4 = copy_paste(img4, labels4, segments4, p=self.hyp['copy_paste'])
'''
Mosaic only experiment
img4, labels4, random_parameters = random_perspective(img4,
labels4,
segments4,
Expand All @@ -846,6 +850,7 @@ def load_mosaic(self, index):
seg4, _, _ = random_perspective(seg4, labels4, segments4, degrees=self.hyp['degrees'], translate=self.hyp['translate'],
scale=self.hyp['scale'], shear=self.hyp['shear'], perspective=self.hyp['perspective'],
border=self.mosaic_border, random_parameters=random_parameters)
'''

return img4, labels4, seg4

Expand Down

0 comments on commit c0954d2

Please sign in to comment.