update mosaic border

pull/1/head
Glenn Jocher 5 years ago
parent 93a6765806
commit 37e13f8846

@ -207,6 +207,10 @@ def train(hyp):
image_weights = labels_to_image_weights(dataset.labels, nc=nc, class_weights=w) image_weights = labels_to_image_weights(dataset.labels, nc=nc, class_weights=w)
dataset.indices = random.choices(range(dataset.n), weights=image_weights, k=dataset.n) # rand weighted idx dataset.indices = random.choices(range(dataset.n), weights=image_weights, k=dataset.n) # rand weighted idx
# Update mosaic border
# b = int(random.uniform(0.25 * imgsz, 0.75 * imgsz + gs) // gs * gs)
# dataset.mosaic_border = [b - imgsz, -b] # height, width borders
mloss = torch.zeros(4, device=device) # mean losses mloss = torch.zeros(4, device=device) # mean losses
print(('\n' + '%10s' * 8) % ('Epoch', 'gpu_mem', 'GIoU', 'obj', 'cls', 'total', 'targets', 'img_size')) print(('\n' + '%10s' * 8) % ('Epoch', 'gpu_mem', 'GIoU', 'obj', 'cls', 'total', 'targets', 'img_size'))
pbar = tqdm(enumerate(dataloader), total=nb) # progress bar pbar = tqdm(enumerate(dataloader), total=nb) # progress bar

@ -307,7 +307,7 @@ class LoadImagesAndLabels(Dataset): # for training/testing
self.image_weights = image_weights self.image_weights = image_weights
self.rect = False if image_weights else rect self.rect = False if image_weights else rect
self.mosaic = self.augment and not self.rect # load 4 images at a time into a mosaic (only during training) self.mosaic = self.augment and not self.rect # load 4 images at a time into a mosaic (only during training)
self.mosaic_border = None self.mosaic_border = [-img_size // 2, -img_size // 2]
self.stride = stride self.stride = stride
@ -588,8 +588,7 @@ def load_mosaic(self, index):
labels4 = [] labels4 = []
s = self.img_size s = self.img_size
border = [-s // 2, -s // 2] # self.mosaic_border yc, xc = [int(random.uniform(-x, 2 * s + x)) for x in self.mosaic_border] # mosaic center x, y
yc, xc = [int(random.uniform(-x, 2 * s + x)) for x in border] # mosaic center x, y
indices = [index] + [random.randint(0, len(self.labels) - 1) for _ in range(3)] # 3 additional image indices indices = [index] + [random.randint(0, len(self.labels) - 1) for _ in range(3)] # 3 additional image indices
for i, index in enumerate(indices): for i, index in enumerate(indices):
# Load image # Load image
@ -637,7 +636,7 @@ def load_mosaic(self, index):
translate=self.hyp['translate'], translate=self.hyp['translate'],
scale=self.hyp['scale'], scale=self.hyp['scale'],
shear=self.hyp['shear'], shear=self.hyp['shear'],
border=border) # border to remove border=self.mosaic_border) # border to remove
return img4, labels4 return img4, labels4

Loading…
Cancel
Save