updates
This commit is contained in:
parent
8d54770859
commit
2bc6683325
45
test.py
45
test.py
|
@ -78,12 +78,15 @@ def test(cfg,
|
|||
if batch_i == 0 and not os.path.exists('test_batch0.jpg'):
|
||||
plot_images(imgs=imgs, targets=targets, paths=paths, fname='test_batch0.jpg')
|
||||
|
||||
# Run model
|
||||
inf_out, train_out = model(imgs) # inference and training outputs
|
||||
# Disable gradients
|
||||
with torch.no_grad():
|
||||
|
||||
# Compute loss
|
||||
if hasattr(model, 'hyp'): # if model has loss hyperparameters
|
||||
loss += compute_loss(train_out, targets, model)[1][:3].cpu() # GIoU, obj, cls
|
||||
# Run model
|
||||
inf_out, train_out = model(imgs) # inference and training outputs
|
||||
|
||||
# Compute loss
|
||||
if hasattr(model, 'hyp'): # if model has loss hyperparameters
|
||||
loss += compute_loss(train_out, targets, model)[1][:3].cpu() # GIoU, obj, cls
|
||||
|
||||
# Run NMS
|
||||
output = non_max_suppression(inf_out, conf_thres=conf_thres, nms_thres=nms_thres)
|
||||
|
@ -220,12 +223,26 @@ if __name__ == '__main__':
|
|||
opt = parser.parse_args()
|
||||
print(opt)
|
||||
|
||||
with torch.no_grad():
|
||||
test(opt.cfg,
|
||||
opt.data,
|
||||
opt.weights,
|
||||
opt.batch_size,
|
||||
opt.img_size,
|
||||
opt.conf_thres,
|
||||
opt.nms_thres,
|
||||
opt.save_json or any([x in opt.data for x in ['coco.data', 'coco2014.data', 'coco2017.data']]))
|
||||
# Test
|
||||
test(opt.cfg,
|
||||
opt.data,
|
||||
opt.weights,
|
||||
opt.batch_size,
|
||||
opt.img_size,
|
||||
opt.conf_thres,
|
||||
opt.nms_thres,
|
||||
opt.save_json or any([x in opt.data for x in ['coco.data', 'coco2014.data', 'coco2017.data']]))
|
||||
|
||||
# # Parameter study
|
||||
# y = []
|
||||
# x = np.arange(0.4, 0.81, 0.1)
|
||||
# for v in x:
|
||||
# y.append(test(opt.cfg, opt.data, opt.weights, opt.batch_size, opt.img_size, 0.1, v, True)[0])
|
||||
# y = np.stack(y, 0)
|
||||
#
|
||||
# fig, ax = plt.subplots(1, 1, figsize=(12, 6))
|
||||
# ax.plot(x, y[:, 2], marker='.', label='mAP@0.5')
|
||||
# ax.plot(x, y[:, 3], marker='.', label='mAP@0.5:0.95')
|
||||
# ax.legend()
|
||||
# fig.tight_layout()
|
||||
# plt.savefig('parameters.jpg', dpi=200)
|
||||
|
|
19
train.py
19
train.py
|
@ -323,16 +323,15 @@ def train():
|
|||
if opt.prebias:
|
||||
print_model_biases(model)
|
||||
elif not opt.notest or final_epoch: # Calculate mAP
|
||||
with torch.no_grad():
|
||||
is_coco = any([x in data for x in ['coco.data', 'coco2014.data', 'coco2017.data']]) and model.nc == 80
|
||||
results, maps = test.test(cfg,
|
||||
data,
|
||||
batch_size=batch_size,
|
||||
img_size=opt.img_size,
|
||||
model=model,
|
||||
conf_thres=0.001 if final_epoch else 0.1, # 0.1 for speed
|
||||
save_json=final_epoch and is_coco,
|
||||
dataloader=testloader)
|
||||
is_coco = any([x in data for x in ['coco.data', 'coco2014.data', 'coco2017.data']]) and model.nc == 80
|
||||
results, maps = test.test(cfg,
|
||||
data,
|
||||
batch_size=batch_size,
|
||||
img_size=opt.img_size,
|
||||
model=model,
|
||||
conf_thres=0.001 if final_epoch else 0.1, # 0.1 for speed
|
||||
save_json=final_epoch and is_coco,
|
||||
dataloader=testloader)
|
||||
|
||||
# Write epoch results
|
||||
with open(results_file, 'a') as f:
|
||||
|
|
Loading…
Reference in New Issue