Commit
·
37e13f8
1
Parent(s):
93a6765
update mosaic border
Browse files- train.py +4 -0
- utils/datasets.py +3 -4
train.py
CHANGED
@@ -207,6 +207,10 @@ def train(hyp):
|
|
207 |
image_weights = labels_to_image_weights(dataset.labels, nc=nc, class_weights=w)
|
208 |
dataset.indices = random.choices(range(dataset.n), weights=image_weights, k=dataset.n) # rand weighted idx
|
209 |
|
|
|
|
|
|
|
|
|
210 |
mloss = torch.zeros(4, device=device) # mean losses
|
211 |
print(('\n' + '%10s' * 8) % ('Epoch', 'gpu_mem', 'GIoU', 'obj', 'cls', 'total', 'targets', 'img_size'))
|
212 |
pbar = tqdm(enumerate(dataloader), total=nb) # progress bar
|
|
|
207 |
image_weights = labels_to_image_weights(dataset.labels, nc=nc, class_weights=w)
|
208 |
dataset.indices = random.choices(range(dataset.n), weights=image_weights, k=dataset.n) # rand weighted idx
|
209 |
|
210 |
+
# Update mosaic border
|
211 |
+
# b = int(random.uniform(0.25 * imgsz, 0.75 * imgsz + gs) // gs * gs)
|
212 |
+
# dataset.mosaic_border = [b - imgsz, -b] # height, width borders
|
213 |
+
|
214 |
mloss = torch.zeros(4, device=device) # mean losses
|
215 |
print(('\n' + '%10s' * 8) % ('Epoch', 'gpu_mem', 'GIoU', 'obj', 'cls', 'total', 'targets', 'img_size'))
|
216 |
pbar = tqdm(enumerate(dataloader), total=nb) # progress bar
|
utils/datasets.py
CHANGED
@@ -307,7 +307,7 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|
307 |
self.image_weights = image_weights
|
308 |
self.rect = False if image_weights else rect
|
309 |
self.mosaic = self.augment and not self.rect # load 4 images at a time into a mosaic (only during training)
|
310 |
-
self.mosaic_border =
|
311 |
self.stride = stride
|
312 |
|
313 |
|
@@ -588,8 +588,7 @@ def load_mosaic(self, index):
|
|
588 |
|
589 |
labels4 = []
|
590 |
s = self.img_size
|
591 |
-
|
592 |
-
yc, xc = [int(random.uniform(-x, 2 * s + x)) for x in border] # mosaic center x, y
|
593 |
indices = [index] + [random.randint(0, len(self.labels) - 1) for _ in range(3)] # 3 additional image indices
|
594 |
for i, index in enumerate(indices):
|
595 |
# Load image
|
@@ -637,7 +636,7 @@ def load_mosaic(self, index):
|
|
637 |
translate=self.hyp['translate'],
|
638 |
scale=self.hyp['scale'],
|
639 |
shear=self.hyp['shear'],
|
640 |
-
border=
|
641 |
|
642 |
return img4, labels4
|
643 |
|
|
|
307 |
self.image_weights = image_weights
|
308 |
self.rect = False if image_weights else rect
|
309 |
self.mosaic = self.augment and not self.rect # load 4 images at a time into a mosaic (only during training)
|
310 |
+
self.mosaic_border = [-img_size // 2, -img_size // 2]
|
311 |
self.stride = stride
|
312 |
|
313 |
|
|
|
588 |
|
589 |
labels4 = []
|
590 |
s = self.img_size
|
591 |
+
yc, xc = [int(random.uniform(-x, 2 * s + x)) for x in self.mosaic_border] # mosaic center x, y
|
|
|
592 |
indices = [index] + [random.randint(0, len(self.labels) - 1) for _ in range(3)] # 3 additional image indices
|
593 |
for i, index in enumerate(indices):
|
594 |
# Load image
|
|
|
636 |
translate=self.hyp['translate'],
|
637 |
scale=self.hyp['scale'],
|
638 |
shear=self.hyp['shear'],
|
639 |
+
border=self.mosaic_border) # border to remove
|
640 |
|
641 |
return img4, labels4
|
642 |
|