glenn-jocher
commited on
Commit
•
4695ca8
1
Parent(s):
0e5cfdb
Refactoring cleanup (#3565)
Browse files* Refactoring cleanup
* Update test.py
detect.py
CHANGED
@@ -178,7 +178,7 @@ if __name__ == '__main__':
|
|
178 |
parser.add_argument('--source', type=str, default='data/images', help='file/dir/URL/glob, 0 for webcam')
|
179 |
parser.add_argument('--imgsz', '--img', '--img-size', type=int, default=640, help='inference size (pixels)')
|
180 |
parser.add_argument('--conf-thres', type=float, default=0.25, help='confidence threshold')
|
181 |
-
parser.add_argument('--iou-thres', type=float, default=0.45, help='NMS
|
182 |
parser.add_argument('--max-det', type=int, default=1000, help='maximum detections per image')
|
183 |
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
|
184 |
parser.add_argument('--view-img', action='store_true', help='show results')
|
|
|
178 |
parser.add_argument('--source', type=str, default='data/images', help='file/dir/URL/glob, 0 for webcam')
|
179 |
parser.add_argument('--imgsz', '--img', '--img-size', type=int, default=640, help='inference size (pixels)')
|
180 |
parser.add_argument('--conf-thres', type=float, default=0.25, help='confidence threshold')
|
181 |
+
parser.add_argument('--iou-thres', type=float, default=0.45, help='NMS IoU threshold')
|
182 |
parser.add_argument('--max-det', type=int, default=1000, help='maximum detections per image')
|
183 |
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
|
184 |
parser.add_argument('--view-img', action='store_true', help='show results')
|
test.py
CHANGED
@@ -20,30 +20,31 @@ from utils.torch_utils import select_device, time_synchronized
|
|
20 |
|
21 |
@torch.no_grad()
|
22 |
def test(data,
|
23 |
-
weights=None,
|
24 |
-
batch_size=32,
|
25 |
-
imgsz=640, #
|
26 |
conf_thres=0.001, # confidence threshold
|
27 |
iou_thres=0.6, # NMS IoU threshold
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
model=None,
|
33 |
dataloader=None,
|
34 |
-
save_dir=Path(''),
|
35 |
-
save_txt=False, # for auto-labelling
|
36 |
-
save_hybrid=False, # for hybrid auto-labelling
|
37 |
-
save_conf=False, # save auto-label confidences
|
38 |
plots=True,
|
39 |
wandb_logger=None,
|
40 |
compute_loss=None,
|
41 |
-
|
42 |
-
project='runs/test',
|
43 |
-
name='exp',
|
44 |
-
exist_ok=False,
|
45 |
-
task='val',
|
46 |
-
device=''):
|
47 |
# Initialize/load model and set device
|
48 |
training = model is not None
|
49 |
if training: # called by train.py
|
@@ -155,7 +156,7 @@ def test(data,
|
|
155 |
with open(save_dir / 'labels' / (path.stem + '.txt'), 'a') as f:
|
156 |
f.write(('%g ' * len(line)).rstrip() % line + '\n')
|
157 |
|
158 |
-
# W&B logging - Media Panel
|
159 |
if len(wandb_images) < log_imgs and wandb_logger.current_epoch > 0: # Check for test operation
|
160 |
if wandb_logger.current_epoch % wandb_logger.bbox_interval == 0:
|
161 |
box_data = [{"position": {"minX": xyxy[0], "minY": xyxy[1], "maxX": xyxy[2], "maxY": xyxy[3]},
|
@@ -295,12 +296,12 @@ def test(data,
|
|
295 |
|
296 |
if __name__ == '__main__':
|
297 |
parser = argparse.ArgumentParser(prog='test.py')
|
|
|
298 |
parser.add_argument('--weights', nargs='+', type=str, default='yolov5s.pt', help='model.pt path(s)')
|
299 |
-
parser.add_argument('--
|
300 |
-
parser.add_argument('--batch-size', type=int, default=32, help='size of each image batch')
|
301 |
parser.add_argument('--imgsz', '--img', '--img-size', type=int, default=640, help='inference size (pixels)')
|
302 |
-
parser.add_argument('--conf-thres', type=float, default=0.001, help='
|
303 |
-
parser.add_argument('--iou-thres', type=float, default=0.6, help='
|
304 |
parser.add_argument('--task', default='val', help='train, val, test, speed or study')
|
305 |
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
|
306 |
parser.add_argument('--single-cls', action='store_true', help='treat as single-class dataset')
|
@@ -326,7 +327,8 @@ if __name__ == '__main__':
|
|
326 |
|
327 |
elif opt.task == 'speed': # speed benchmarks
|
328 |
for w in opt.weights if isinstance(opt.weights, list) else [opt.weights]:
|
329 |
-
test(opt.data, w, opt.batch_size, opt.imgsz,
|
|
|
330 |
|
331 |
elif opt.task == 'study': # run over a range of settings and save/plot
|
332 |
# python test.py --task study --data coco.yaml --iou 0.7 --weights yolov5s.pt yolov5m.pt yolov5l.pt yolov5x.pt
|
@@ -336,8 +338,8 @@ if __name__ == '__main__':
|
|
336 |
y = [] # y axis
|
337 |
for i in x: # img-size
|
338 |
print(f'\nRunning {f} point {i}...')
|
339 |
-
r, _, t = test(opt.data, w, opt.batch_size, i, opt.conf_thres,
|
340 |
-
plots=False)
|
341 |
y.append(r + t) # results and times
|
342 |
np.savetxt(f, y, fmt='%10.4g') # save
|
343 |
os.system('zip -r study.zip study_*.txt')
|
|
|
20 |
|
21 |
@torch.no_grad()
|
22 |
def test(data,
|
23 |
+
weights=None, # model.pt path(s)
|
24 |
+
batch_size=32, # batch size
|
25 |
+
imgsz=640, # inference size (pixels)
|
26 |
conf_thres=0.001, # confidence threshold
|
27 |
iou_thres=0.6, # NMS IoU threshold
|
28 |
+
task='val', # train, val, test, speed or study
|
29 |
+
device='', # cuda device, i.e. 0 or 0,1,2,3 or cpu
|
30 |
+
single_cls=False, # treat as single-class dataset
|
31 |
+
augment=False, # augmented inference
|
32 |
+
verbose=False, # verbose output
|
33 |
+
save_txt=False, # save results to *.txt
|
34 |
+
save_hybrid=False, # save label+prediction hybrid results to *.txt
|
35 |
+
save_conf=False, # save confidences in --save-txt labels
|
36 |
+
save_json=False, # save a cocoapi-compatible JSON results file
|
37 |
+
project='runs/test', # save to project/name
|
38 |
+
name='exp', # save to project/name
|
39 |
+
exist_ok=False, # existing project/name ok, do not increment
|
40 |
+
half=True, # use FP16 half-precision inference
|
41 |
model=None,
|
42 |
dataloader=None,
|
43 |
+
save_dir=Path(''),
|
|
|
|
|
|
|
44 |
plots=True,
|
45 |
wandb_logger=None,
|
46 |
compute_loss=None,
|
47 |
+
):
|
|
|
|
|
|
|
|
|
|
|
48 |
# Initialize/load model and set device
|
49 |
training = model is not None
|
50 |
if training: # called by train.py
|
|
|
156 |
with open(save_dir / 'labels' / (path.stem + '.txt'), 'a') as f:
|
157 |
f.write(('%g ' * len(line)).rstrip() % line + '\n')
|
158 |
|
159 |
+
# W&B logging - Media Panel plots
|
160 |
if len(wandb_images) < log_imgs and wandb_logger.current_epoch > 0: # Check for test operation
|
161 |
if wandb_logger.current_epoch % wandb_logger.bbox_interval == 0:
|
162 |
box_data = [{"position": {"minX": xyxy[0], "minY": xyxy[1], "maxX": xyxy[2], "maxY": xyxy[3]},
|
|
|
296 |
|
297 |
if __name__ == '__main__':
|
298 |
parser = argparse.ArgumentParser(prog='test.py')
|
299 |
+
parser.add_argument('--data', type=str, default='data/coco128.yaml', help='dataset.yaml path')
|
300 |
parser.add_argument('--weights', nargs='+', type=str, default='yolov5s.pt', help='model.pt path(s)')
|
301 |
+
parser.add_argument('--batch-size', type=int, default=32, help='batch size')
|
|
|
302 |
parser.add_argument('--imgsz', '--img', '--img-size', type=int, default=640, help='inference size (pixels)')
|
303 |
+
parser.add_argument('--conf-thres', type=float, default=0.001, help='confidence threshold')
|
304 |
+
parser.add_argument('--iou-thres', type=float, default=0.6, help='NMS IoU threshold')
|
305 |
parser.add_argument('--task', default='val', help='train, val, test, speed or study')
|
306 |
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
|
307 |
parser.add_argument('--single-cls', action='store_true', help='treat as single-class dataset')
|
|
|
327 |
|
328 |
elif opt.task == 'speed': # speed benchmarks
|
329 |
for w in opt.weights if isinstance(opt.weights, list) else [opt.weights]:
|
330 |
+
test(opt.data, weights=w, batch_size=opt.batch_size, imgsz=opt.imgsz, conf_thres=.25, iou_thres=.45,
|
331 |
+
save_json=False, plots=False)
|
332 |
|
333 |
elif opt.task == 'study': # run over a range of settings and save/plot
|
334 |
# python test.py --task study --data coco.yaml --iou 0.7 --weights yolov5s.pt yolov5m.pt yolov5l.pt yolov5x.pt
|
|
|
338 |
y = [] # y axis
|
339 |
for i in x: # img-size
|
340 |
print(f'\nRunning {f} point {i}...')
|
341 |
+
r, _, t = test(opt.data, weights=w, batch_size=opt.batch_size, imgsz=i, conf_thres=opt.conf_thres,
|
342 |
+
iou_thres=opt.iou_thres, save_json=opt.save_json, plots=False)
|
343 |
y.append(r + t) # results and times
|
344 |
np.savetxt(f, y, fmt='%10.4g') # save
|
345 |
os.system('zip -r study.zip study_*.txt')
|
train.py
CHANGED
@@ -454,7 +454,7 @@ if __name__ == '__main__':
|
|
454 |
parser = argparse.ArgumentParser()
|
455 |
parser.add_argument('--weights', type=str, default='yolov5s.pt', help='initial weights path')
|
456 |
parser.add_argument('--cfg', type=str, default='', help='model.yaml path')
|
457 |
-
parser.add_argument('--data', type=str, default='data/coco128.yaml', help='
|
458 |
parser.add_argument('--hyp', type=str, default='data/hyp.scratch.yaml', help='hyperparameters path')
|
459 |
parser.add_argument('--epochs', type=int, default=300)
|
460 |
parser.add_argument('--batch-size', type=int, default=16, help='total batch size for all GPUs')
|
|
|
454 |
parser = argparse.ArgumentParser()
|
455 |
parser.add_argument('--weights', type=str, default='yolov5s.pt', help='initial weights path')
|
456 |
parser.add_argument('--cfg', type=str, default='', help='model.yaml path')
|
457 |
+
parser.add_argument('--data', type=str, default='data/coco128.yaml', help='dataset.yaml path')
|
458 |
parser.add_argument('--hyp', type=str, default='data/hyp.scratch.yaml', help='hyperparameters path')
|
459 |
parser.add_argument('--epochs', type=int, default=300)
|
460 |
parser.add_argument('--batch-size', type=int, default=16, help='total batch size for all GPUs')
|