Explicit opt function arguments (#2817)
* more explicit function arguments * fix typo in detect.py * revert import order * revert import order * remove default value
This commit is contained in:
1 parent
264d860f8d
commit
b40dd99167
2 files changed
+8
-6
No files matched your search
@@ -15,7 +15,7 @@ from utils.plots import plot_one_box
|
|||||||
from utils.torch_utils import select_device, load_classifier, time_synchronized
|
from utils.torch_utils import select_device, load_classifier, time_synchronized
|
||||||
|
|
||||||
|
|
||||||
def detect():
|
def detect(opt):
|
||||||
source, weights, view_img, save_txt, imgsz = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size
|
source, weights, view_img, save_txt, imgsz = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size
|
||||||
save_img = not opt.nosave and not source.endswith('.txt') # save inference images
|
save_img = not opt.nosave and not source.endswith('.txt') # save inference images
|
||||||
webcam = source.isnumeric() or source.endswith('.txt') or source.lower().startswith(
|
webcam = source.isnumeric() or source.endswith('.txt') or source.lower().startswith(
|
||||||
@@ -176,7 +176,7 @@ if __name__ == '__main__':
|
|||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
if opt.update: # update all models (to fix SourceChangeWarning)
|
if opt.update: # update all models (to fix SourceChangeWarning)
|
||||||
for opt.weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']:
|
for opt.weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']:
|
||||||
detect()
|
detect(opt=opt)
|
||||||
strip_optimizer(opt.weights)
|
strip_optimizer(opt.weights)
|
||||||
else:
|
else:
|
||||||
detect()
|
detect(opt=opt)
|
||||||
@@ -38,7 +38,8 @@ def test(data,
|
|||||||
wandb_logger=None,
|
wandb_logger=None,
|
||||||
compute_loss=None,
|
compute_loss=None,
|
||||||
half_precision=True,
|
half_precision=True,
|
||||||
is_coco=False):
|
is_coco=False,
|
||||||
|
opt=None):
|
||||||
# Initialize/load model and set device
|
# Initialize/load model and set device
|
||||||
training = model is not None
|
training = model is not None
|
||||||
if training: # called by train.py
|
if training: # called by train.py
|
||||||
@@ -323,11 +324,12 @@ if __name__ == '__main__':
|
|||||||
save_txt=opt.save_txt | opt.save_hybrid,
|
save_txt=opt.save_txt | opt.save_hybrid,
|
||||||
save_hybrid=opt.save_hybrid,
|
save_hybrid=opt.save_hybrid,
|
||||||
save_conf=opt.save_conf,
|
save_conf=opt.save_conf,
|
||||||
|
opt=opt
|
||||||
)
|
)
|
||||||
|
|
||||||
elif opt.task == 'speed': # speed benchmarks
|
elif opt.task == 'speed': # speed benchmarks
|
||||||
for w in opt.weights:
|
for w in opt.weights:
|
||||||
test(opt.data, w, opt.batch_size, opt.img_size, 0.25, 0.45, save_json=False, plots=False)
|
test(opt.data, w, opt.batch_size, opt.img_size, 0.25, 0.45, save_json=False, plots=False, opt=opt)
|
||||||
|
|
||||||
elif opt.task == 'study': # run over a range of settings and save/plot
|
elif opt.task == 'study': # run over a range of settings and save/plot
|
||||||
# python test.py --task study --data coco.yaml --iou 0.7 --weights yolov5s.pt yolov5m.pt yolov5l.pt yolov5x.pt
|
# 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__':
|
|||||||
for i in x: # img-size
|
for i in x: # img-size
|
||||||
print(f'\nRunning {f} point {i}...')
|
print(f'\nRunning {f} point {i}...')
|
||||||
r, _, t = test(opt.data, w, opt.batch_size, i, opt.conf_thres, opt.iou_thres, opt.save_json,
|
r, _, t = test(opt.data, w, opt.batch_size, i, opt.conf_thres, opt.iou_thres, opt.save_json,
|
||||||
plots=False)
|
plots=False, opt=opt)
|
||||||
y.append(r + t) # results and times
|
y.append(r + t) # results and times
|
||||||
np.savetxt(f, y, fmt='%10.4g') # save
|
np.savetxt(f, y, fmt='%10.4g') # save
|
||||||
os.system('zip -r study.zip study_*.txt')
|
os.system('zip -r study.zip study_*.txt')
|
||||||
|
|||||||
Reference in new issue
Block a user