glenn-jocher commited on
Commit
30bc089
1 Parent(s): 61c5019

Update val.py `speed` and `study` tasks (#5608)

Browse files

Accepts all arguments now by default resolving https://github.com/ultralytics/yolov5/issues/5600

Files changed (1) hide show
  1. val.py +21 -20
val.py CHANGED
@@ -339,26 +339,27 @@ def main(opt):
339
  LOGGER.info(f'WARNING: confidence threshold {opt.conf_thres} >> 0.001 will produce invalid mAP values.')
340
  run(**vars(opt))
341
 
342
- elif opt.task == 'speed': # speed benchmarks
343
- # python val.py --task speed --data coco.yaml --batch 1 --weights yolov5n.pt yolov5s.pt...
344
- for w in opt.weights if isinstance(opt.weights, list) else [opt.weights]:
345
- run(opt.data, weights=w, batch_size=opt.batch_size, imgsz=opt.imgsz, conf_thres=.25, iou_thres=.45,
346
- device=opt.device, save_json=False, plots=False)
347
-
348
- elif opt.task == 'study': # run over a range of settings and save/plot
349
- # python val.py --task study --data coco.yaml --iou 0.7 --weights yolov5n.pt yolov5s.pt...
350
- x = list(range(256, 1536 + 128, 128)) # x axis (image sizes)
351
- for w in opt.weights if isinstance(opt.weights, list) else [opt.weights]:
352
- f = f'study_{Path(opt.data).stem}_{Path(w).stem}.txt' # filename to save to
353
- y = [] # y axis
354
- for i in x: # img-size
355
- LOGGER.info(f'\nRunning {f} point {i}...')
356
- r, _, t = run(opt.data, weights=w, batch_size=opt.batch_size, imgsz=i, conf_thres=opt.conf_thres,
357
- iou_thres=opt.iou_thres, device=opt.device, save_json=opt.save_json, plots=False)
358
- y.append(r + t) # results and times
359
- np.savetxt(f, y, fmt='%10.4g') # save
360
- os.system('zip -r study.zip study_*.txt')
361
- plot_val_study(x=x) # plot
 
362
 
363
 
364
  if __name__ == "__main__":
 
339
  LOGGER.info(f'WARNING: confidence threshold {opt.conf_thres} >> 0.001 will produce invalid mAP values.')
340
  run(**vars(opt))
341
 
342
+ else:
343
+ weights = opt.weights if isinstance(opt.weights, list) else [opt.weights]
344
+ opt.half = True # FP16 for fastest results
345
+ if opt.task == 'speed': # speed benchmarks
346
+ # python val.py --task speed --data coco.yaml --batch 1 --weights yolov5n.pt yolov5s.pt...
347
+ opt.conf_thres, opt.iou_thres, opt.save_json = 0.25, 0.45, False
348
+ for opt.weights in weights:
349
+ run(**vars(opt), plots=False)
350
+
351
+ elif opt.task == 'study': # speed vs mAP benchmarks
352
+ # python val.py --task study --data coco.yaml --iou 0.7 --weights yolov5n.pt yolov5s.pt...
353
+ for opt.weights in weights:
354
+ f = f'study_{Path(opt.data).stem}_{Path(opt.weights).stem}.txt' # filename to save to
355
+ x, y = list(range(256, 1536 + 128, 128)), [] # x axis (image sizes), y axis
356
+ for opt.imgsz in x: # img-size
357
+ LOGGER.info(f'\nRunning {f} --imgsz {opt.imgsz}...')
358
+ r, _, t = run(**vars(opt), plots=False)
359
+ y.append(r + t) # results and times
360
+ np.savetxt(f, y, fmt='%10.4g') # save
361
+ os.system('zip -r study.zip study_*.txt')
362
+ plot_val_study(x=x) # plot
363
 
364
 
365
  if __name__ == "__main__":