fcakyon commited on
Commit
b40dd99
1 Parent(s): 264d860

Explicit opt function arguments (#2817)

Browse files

* more explicit function arguments

* fix typo in detect.py

* revert import order

* revert import order

* remove default value

Files changed (2) hide show
  1. detect.py +3 -3
  2. test.py +5 -3
detect.py CHANGED
@@ -15,7 +15,7 @@ from utils.plots import plot_one_box
15
  from utils.torch_utils import select_device, load_classifier, time_synchronized
16
 
17
 
18
- def detect():
19
  source, weights, view_img, save_txt, imgsz = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size
20
  save_img = not opt.nosave and not source.endswith('.txt') # save inference images
21
  webcam = source.isnumeric() or source.endswith('.txt') or source.lower().startswith(
@@ -176,7 +176,7 @@ if __name__ == '__main__':
176
  with torch.no_grad():
177
  if opt.update: # update all models (to fix SourceChangeWarning)
178
  for opt.weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']:
179
- detect()
180
  strip_optimizer(opt.weights)
181
  else:
182
- detect()
 
15
  from utils.torch_utils import select_device, load_classifier, time_synchronized
16
 
17
 
18
+ def detect(opt):
19
  source, weights, view_img, save_txt, imgsz = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size
20
  save_img = not opt.nosave and not source.endswith('.txt') # save inference images
21
  webcam = source.isnumeric() or source.endswith('.txt') or source.lower().startswith(
 
176
  with torch.no_grad():
177
  if opt.update: # update all models (to fix SourceChangeWarning)
178
  for opt.weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']:
179
+ detect(opt=opt)
180
  strip_optimizer(opt.weights)
181
  else:
182
+ detect(opt=opt)
test.py CHANGED
@@ -38,7 +38,8 @@ def test(data,
38
  wandb_logger=None,
39
  compute_loss=None,
40
  half_precision=True,
41
- is_coco=False):
 
42
  # Initialize/load model and set device
43
  training = model is not None
44
  if training: # called by train.py
@@ -323,11 +324,12 @@ if __name__ == '__main__':
323
  save_txt=opt.save_txt | opt.save_hybrid,
324
  save_hybrid=opt.save_hybrid,
325
  save_conf=opt.save_conf,
 
326
  )
327
 
328
  elif opt.task == 'speed': # speed benchmarks
329
  for w in opt.weights:
330
- test(opt.data, w, opt.batch_size, opt.img_size, 0.25, 0.45, save_json=False, plots=False)
331
 
332
  elif opt.task == 'study': # run over a range of settings and save/plot
333
  # python test.py --task study --data coco.yaml --iou 0.7 --weights yolov5s.pt yolov5m.pt yolov5l.pt yolov5x.pt
@@ -338,7 +340,7 @@ if __name__ == '__main__':
338
  for i in x: # img-size
339
  print(f'\nRunning {f} point {i}...')
340
  r, _, t = test(opt.data, w, opt.batch_size, i, opt.conf_thres, opt.iou_thres, opt.save_json,
341
- plots=False)
342
  y.append(r + t) # results and times
343
  np.savetxt(f, y, fmt='%10.4g') # save
344
  os.system('zip -r study.zip study_*.txt')
 
38
  wandb_logger=None,
39
  compute_loss=None,
40
  half_precision=True,
41
+ is_coco=False,
42
+ opt=None):
43
  # Initialize/load model and set device
44
  training = model is not None
45
  if training: # called by train.py
 
324
  save_txt=opt.save_txt | opt.save_hybrid,
325
  save_hybrid=opt.save_hybrid,
326
  save_conf=opt.save_conf,
327
+ opt=opt
328
  )
329
 
330
  elif opt.task == 'speed': # speed benchmarks
331
  for w in opt.weights:
332
+ test(opt.data, w, opt.batch_size, opt.img_size, 0.25, 0.45, save_json=False, plots=False, opt=opt)
333
 
334
  elif opt.task == 'study': # run over a range of settings and save/plot
335
  # python test.py --task study --data coco.yaml --iou 0.7 --weights yolov5s.pt yolov5m.pt yolov5l.pt yolov5x.pt
 
340
  for i in x: # img-size
341
  print(f'\nRunning {f} point {i}...')
342
  r, _, t = test(opt.data, w, opt.batch_size, i, opt.conf_thres, opt.iou_thres, opt.save_json,
343
+ plots=False, opt=opt)
344
  y.append(r + t) # results and times
345
  np.savetxt(f, y, fmt='%10.4g') # save
346
  os.system('zip -r study.zip study_*.txt')