Skip to content

Commit

Permalink
Fixing minor multi-streaming issues with TensoRT engine (#6504)
Browse files Browse the repository at this point in the history
* Update batch-size in model.warmup() + indentation for logging inference results

* These changes are in response to PR comments

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
greg2451 and pre-commit-ci[bot] authored Feb 4, 2022
1 parent 079b36d commit 8fcdf3b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=(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()
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion val.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8fcdf3b

Please sign in to comment.