From 111fccd2bb416a69bf1c219b9e4a042465451e6c Mon Sep 17 00:00:00 2001 From: greg2451 Date: Wed, 2 Feb 2022 10:16:57 +0100 Subject: [PATCH 1/3] Update batch-size in model.warmup() + indentation for logging inference results --- detect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/detect.py b/detect.py index 9b553faa34e4..e6d657332923 100644 --- a/detect.py +++ b/detect.py @@ -110,7 +110,7 @@ def run(weights=ROOT / 'yolov5s.pt', # model.pt path(s) vid_path, vid_writer = [None] * bs, [None] * bs # Run inference - model.warmup(imgsz=(1, 3, *imgsz), half=half) # warmup + model.warmup(imgsz=(bs, 3, *imgsz), half=half) # warmup dt, seen = [0.0, 0.0, 0.0], 0 for path, im, im0s, vid_cap, s in dataset: t1 = time_sync() @@ -175,9 +175,6 @@ def run(weights=ROOT / 'yolov5s.pt', # model.pt path(s) if save_crop: save_one_box(xyxy, imc, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True) - # Print time (inference-only) - LOGGER.info(f'{s}Done. ({t3 - t2:.3f}s)') - # Stream results im0 = annotator.result() if view_img: @@ -203,6 +200,9 @@ def run(weights=ROOT / 'yolov5s.pt', # model.pt path(s) vid_writer[i] = cv2.VideoWriter(save_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (w, h)) vid_writer[i].write(im0) + # Print time (inference-only) + LOGGER.info(f'{s}Done. ({t3 - t2:.3f}s)') + # Print results t = tuple(x / seen * 1E3 for x in dt) # speeds per image LOGGER.info(f'Speed: %.1fms pre-process, %.1fms inference, %.1fms NMS per image at shape {(1, 3, *imgsz)}' % t) From ee0dd8d7dfd9e4b10f6a9d9b614f78bc0c407203 Mon Sep 17 00:00:00 2001 From: greg2451 Date: Fri, 4 Feb 2022 17:40:05 +0100 Subject: [PATCH 2/3] These changes are in response to PR comments --- detect.py | 2 +- val.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/detect.py b/detect.py index e6d657332923..76f67bea1b90 100644 --- a/detect.py +++ b/detect.py @@ -110,7 +110,7 @@ def run(weights=ROOT / 'yolov5s.pt', # model.pt path(s) vid_path, vid_writer = [None] * bs, [None] * bs # Run inference - model.warmup(imgsz=(bs, 3, *imgsz), half=half) # warmup + model.warmup(imgsz=(1 if pt else bs, 3, *imgsz), half=half) # warmup dt, seen = [0.0, 0.0, 0.0], 0 for path, im, im0s, vid_cap, s in dataset: t1 = time_sync() diff --git a/val.py b/val.py index 843943b5ff7e..451960b98916 100644 --- a/val.py +++ b/val.py @@ -162,7 +162,7 @@ def run(data, # Dataloader if not training: - model.warmup(imgsz=(1, 3, imgsz, imgsz), half=half) # warmup + model.warmup(imgsz=(1 if pt else batch_size, 3, imgsz, imgsz), half=half) # warmup pad = 0.0 if task == 'speed' else 0.5 task = task if task in ('train', 'val', 'test') else 'val' # path to train/val/test images dataloader = create_dataloader(data[task], imgsz, batch_size, stride, single_cls, pad=pad, rect=pt, From f81cada2db0adb92ec3b805535680c3c17c3a8ca Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Feb 2022 16:41:07 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- val.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/val.py b/val.py index 451960b98916..90debaf0dd60 100644 --- a/val.py +++ b/val.py @@ -162,7 +162,7 @@ def run(data, # Dataloader if not training: - model.warmup(imgsz=(1 if pt else batch_size, 3, imgsz, imgsz), half=half) # warmup + model.warmup(imgsz=(1 if pt else batch_size, 3, imgsz, imgsz), half=half) # warmup pad = 0.0 if task == 'speed' else 0.5 task = task if task in ('train', 'val', 'test') else 'val' # path to train/val/test images dataloader = create_dataloader(data[task], imgsz, batch_size, stride, single_cls, pad=pad, rect=pt,