|
|
@ -155,38 +155,15 @@ def train(hyp):
|
|
|
|
model = torch.nn.parallel.DistributedDataParallel(model)
|
|
|
|
model = torch.nn.parallel.DistributedDataParallel(model)
|
|
|
|
# pip install torch==1.4.0+cu100 torchvision==0.5.0+cu100 -f https://download.pytorch.org/whl/torch_stable.html
|
|
|
|
# pip install torch==1.4.0+cu100 torchvision==0.5.0+cu100 -f https://download.pytorch.org/whl/torch_stable.html
|
|
|
|
|
|
|
|
|
|
|
|
# Dataset
|
|
|
|
# Trainloader
|
|
|
|
dataset = LoadImagesAndLabels(train_path, imgsz, batch_size,
|
|
|
|
dataloader, dataset = create_dataloader(train_path, imgsz, batch_size, gs, opt,
|
|
|
|
augment=True,
|
|
|
|
hyp=hyp, augment=True, cache=opt.cache_images, rect=opt.rect)
|
|
|
|
hyp=hyp, # augmentation hyperparameters
|
|
|
|
|
|
|
|
rect=opt.rect, # rectangular training
|
|
|
|
|
|
|
|
cache_images=opt.cache_images,
|
|
|
|
|
|
|
|
single_cls=opt.single_cls,
|
|
|
|
|
|
|
|
stride=gs)
|
|
|
|
|
|
|
|
mlc = np.concatenate(dataset.labels, 0)[:, 0].max() # max label class
|
|
|
|
mlc = np.concatenate(dataset.labels, 0)[:, 0].max() # max label class
|
|
|
|
assert mlc < nc, 'Label class %g exceeds nc=%g in %s. Correct your labels or your model.' % (mlc, nc, opt.cfg)
|
|
|
|
assert mlc < nc, 'Label class %g exceeds nc=%g in %s. Correct your labels or your model.' % (mlc, nc, opt.cfg)
|
|
|
|
|
|
|
|
|
|
|
|
# Dataloader
|
|
|
|
|
|
|
|
batch_size = min(batch_size, len(dataset))
|
|
|
|
|
|
|
|
nw = min([os.cpu_count(), batch_size if batch_size > 1 else 0, 8]) # number of workers
|
|
|
|
|
|
|
|
dataloader = torch.utils.data.DataLoader(dataset,
|
|
|
|
|
|
|
|
batch_size=batch_size,
|
|
|
|
|
|
|
|
num_workers=nw,
|
|
|
|
|
|
|
|
shuffle=not opt.rect, # Shuffle=True unless rectangular training is used
|
|
|
|
|
|
|
|
pin_memory=True,
|
|
|
|
|
|
|
|
collate_fn=dataset.collate_fn)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Testloader
|
|
|
|
# Testloader
|
|
|
|
testloader = torch.utils.data.DataLoader(LoadImagesAndLabels(test_path, imgsz_test, batch_size,
|
|
|
|
testloader = create_dataloader(test_path, imgsz_test, batch_size, gs, opt,
|
|
|
|
hyp=hyp,
|
|
|
|
hyp=hyp, augment=False, cache=opt.cache_images, rect=True)[0]
|
|
|
|
rect=True,
|
|
|
|
|
|
|
|
cache_images=opt.cache_images,
|
|
|
|
|
|
|
|
single_cls=opt.single_cls,
|
|
|
|
|
|
|
|
stride=gs),
|
|
|
|
|
|
|
|
batch_size=batch_size,
|
|
|
|
|
|
|
|
num_workers=nw,
|
|
|
|
|
|
|
|
pin_memory=True,
|
|
|
|
|
|
|
|
collate_fn=dataset.collate_fn)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Model parameters
|
|
|
|
# Model parameters
|
|
|
|
hyp['cls'] *= nc / 80. # scale coco-tuned hyp['cls'] to current dataset
|
|
|
|
hyp['cls'] *= nc / 80. # scale coco-tuned hyp['cls'] to current dataset
|
|
|
@ -218,7 +195,7 @@ def train(hyp):
|
|
|
|
maps = np.zeros(nc) # mAP per class
|
|
|
|
maps = np.zeros(nc) # mAP per class
|
|
|
|
results = (0, 0, 0, 0, 0, 0, 0) # 'P', 'R', 'mAP', 'F1', 'val GIoU', 'val Objectness', 'val Classification'
|
|
|
|
results = (0, 0, 0, 0, 0, 0, 0) # 'P', 'R', 'mAP', 'F1', 'val GIoU', 'val Objectness', 'val Classification'
|
|
|
|
print('Image sizes %g train, %g test' % (imgsz, imgsz_test))
|
|
|
|
print('Image sizes %g train, %g test' % (imgsz, imgsz_test))
|
|
|
|
print('Using %g dataloader workers' % nw)
|
|
|
|
print('Using %g dataloader workers' % dataloader.num_workers)
|
|
|
|
print('Starting training for %g epochs...' % epochs)
|
|
|
|
print('Starting training for %g epochs...' % epochs)
|
|
|
|
# torch.autograd.set_detect_anomaly(True)
|
|
|
|
# torch.autograd.set_detect_anomaly(True)
|
|
|
|
for epoch in range(start_epoch, epochs): # epoch ------------------------------------------------------------------
|
|
|
|
for epoch in range(start_epoch, epochs): # epoch ------------------------------------------------------------------
|
|
|
|