From 4d36773be4bf4864f6221ab588af065807d274bd Mon Sep 17 00:00:00 2001 From: fcakyon Date: Fri, 16 Apr 2021 15:09:05 +0300 Subject: [PATCH 1/5] more explicit function arguments --- detect.py | 16 +++++++++------- test.py | 18 +++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/detect.py b/detect.py index c0707da69e6a..175cd53eb3b2 100644 --- a/detect.py +++ b/detect.py @@ -8,14 +8,16 @@ from numpy import random from models.experimental import attempt_load -from utils.datasets import LoadStreams, LoadImages -from utils.general import check_img_size, check_requirements, check_imshow, non_max_suppression, apply_classifier, \ - scale_coords, xyxy2xywh, strip_optimizer, set_logging, increment_path +from utils.datasets import LoadImages, LoadStreams +from utils.general import (apply_classifier, check_img_size, check_imshow, + check_requirements, increment_path, + non_max_suppression, scale_coords, set_logging, + strip_optimizer, xyxy2xywh) from utils.plots import plot_one_box -from utils.torch_utils import select_device, load_classifier, time_synchronized +from utils.torch_utils import load_classifier, select_device, time_synchronized -def detect(save_img=False): +def detect(save_img=False, opt=opt): 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 webcam = source.isnumeric() or source.endswith('.txt') or source.lower().startswith( @@ -172,7 +174,7 @@ def detect(save_img=False): with torch.no_grad(): if opt.update: # update all models (to fix SourceChangeWarning) for opt.weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']: - detect() + detect(opt=opt) strip_optimizer(opt.weights) else: - detect() + detect(opt=opt) diff --git a/test.py b/test.py index d099699bcad8..1e48876b28e6 100644 --- a/test.py +++ b/test.py @@ -11,10 +11,12 @@ from models.experimental import attempt_load from utils.datasets import create_dataloader -from utils.general import coco80_to_coco91_class, check_dataset, check_file, check_img_size, check_requirements, \ - box_iou, non_max_suppression, scale_coords, xyxy2xywh, xywh2xyxy, set_logging, increment_path, colorstr -from utils.metrics import ap_per_class, ConfusionMatrix -from utils.plots import plot_images, output_to_target, plot_study_txt +from utils.general import (box_iou, check_dataset, check_file, check_img_size, + check_requirements, coco80_to_coco91_class, + colorstr, increment_path, non_max_suppression, + scale_coords, set_logging, xywh2xyxy, xyxy2xywh) +from utils.metrics import ConfusionMatrix, ap_per_class +from utils.plots import output_to_target, plot_images, plot_study_txt from utils.torch_utils import select_device, time_synchronized @@ -38,7 +40,8 @@ def test(data, wandb_logger=None, compute_loss=None, half_precision=True, - is_coco=False): + is_coco=False, + opt=None): # Initialize/load model and set device training = model is not None if training: # called by train.py @@ -323,11 +326,12 @@ def test(data, save_txt=opt.save_txt | opt.save_hybrid, save_hybrid=opt.save_hybrid, save_conf=opt.save_conf, + opt=opt ) elif opt.task == 'speed': # speed benchmarks 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 # python test.py --task study --data coco.yaml --iou 0.7 --weights yolov5s.pt yolov5m.pt yolov5l.pt yolov5x.pt @@ -338,7 +342,7 @@ def test(data, for i in x: # img-size 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, - plots=False) + plots=False, opt=opt) y.append(r + t) # results and times np.savetxt(f, y, fmt='%10.4g') # save os.system('zip -r study.zip study_*.txt') From 02b797c61b6a1ff04531236185ee16330ba7ece2 Mon Sep 17 00:00:00 2001 From: fcakyon Date: Fri, 16 Apr 2021 18:34:00 +0300 Subject: [PATCH 2/5] fix typo in detect.py --- detect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detect.py b/detect.py index 175cd53eb3b2..a237bfed98b1 100644 --- a/detect.py +++ b/detect.py @@ -17,7 +17,7 @@ from utils.torch_utils import load_classifier, select_device, time_synchronized -def detect(save_img=False, opt=opt): +def detect(save_img=False, opt=None): 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 webcam = source.isnumeric() or source.endswith('.txt') or source.lower().startswith( From c5e80c7532e598f1fd3fb76aa5a17b372aeb23ef Mon Sep 17 00:00:00 2001 From: fcakyon <34196005+fcakyon@users.noreply.github.com> Date: Thu, 22 Apr 2021 16:24:24 +0300 Subject: [PATCH 3/5] revert import order --- test.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test.py b/test.py index 481986a224ce..91b2b981c45b 100644 --- a/test.py +++ b/test.py @@ -11,12 +11,10 @@ from models.experimental import attempt_load from utils.datasets import create_dataloader -from utils.general import (box_iou, check_dataset, check_file, check_img_size, - check_requirements, coco80_to_coco91_class, - colorstr, increment_path, non_max_suppression, - scale_coords, set_logging, xywh2xyxy, xyxy2xywh) -from utils.metrics import ConfusionMatrix, ap_per_class -from utils.plots import output_to_target, plot_images, plot_study_txt +from utils.general import coco80_to_coco91_class, check_dataset, check_file, check_img_size, check_requirements, \ + box_iou, non_max_suppression, scale_coords, xyxy2xywh, xywh2xyxy, set_logging, increment_path, colorstr +from utils.metrics import ap_per_class, ConfusionMatrix +from utils.plots import plot_images, output_to_target, plot_study_txt from utils.torch_utils import select_device, time_synchronized From 3e3c20edc9137c448bac156a93e0e070b40a0b6a Mon Sep 17 00:00:00 2001 From: fcakyon <34196005+fcakyon@users.noreply.github.com> Date: Thu, 22 Apr 2021 16:25:08 +0300 Subject: [PATCH 4/5] revert import order --- detect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detect.py b/detect.py index 2b5beaa29515..6320c4e9ea90 100644 --- a/detect.py +++ b/detect.py @@ -12,7 +12,7 @@ from utils.general import check_img_size, check_requirements, check_imshow, non_max_suppression, apply_classifier, \ scale_coords, xyxy2xywh, strip_optimizer, set_logging, increment_path, save_one_box from utils.plots import plot_one_box -from utils.torch_utils import load_classifier, select_device, time_synchronized +from utils.torch_utils import select_device, load_classifier, time_synchronized def detect(opt=None): From 7502143fa0d074827bd23ea717022a438781f378 Mon Sep 17 00:00:00 2001 From: fcakyon <34196005+fcakyon@users.noreply.github.com> Date: Thu, 22 Apr 2021 19:03:33 +0300 Subject: [PATCH 5/5] remove default value --- detect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detect.py b/detect.py index 6320c4e9ea90..d90d2aa8c4f5 100644 --- a/detect.py +++ b/detect.py @@ -15,7 +15,7 @@ from utils.torch_utils import select_device, load_classifier, time_synchronized -def detect(opt=None): +def detect(opt): 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 webcam = source.isnumeric() or source.endswith('.txt') or source.lower().startswith(