Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file output in yolov7 demo #57

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion tools/mc_demo_yolov7.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ def detect(save_img=False):
# Create tracker
tracker = BoTSORT(opt, frame_rate=30.0)

final_results = []

# Run inference
if device.type != 'cpu':
model(torch.zeros(1, 3, imgsz, imgsz).to(device).type_as(next(model.parameters()))) # run once
t0 = time.time()
for path, img, im0s, vid_cap in dataset:
for frame_id, (path, img, im0s, vid_cap) in enumerate(dataset):
img = torch.from_numpy(img).to(device)
img = img.half() if half else img.float() # uint8 to fp16/32
img /= 255.0 # 0 - 255 to 0.0 - 1.0
Expand Down Expand Up @@ -155,6 +157,8 @@ def detect(save_img=False):
p = Path(p) # to Path
save_path = str(save_dir / p.name) # img.jpg

final_results.append((frame_id + 1, online_tlwhs, online_ids, online_scores))

# Print time (inference + NMS)
# print(f'{s}Done. ({t2 - t1:.3f}s)')

Expand Down Expand Up @@ -185,6 +189,8 @@ def detect(save_img=False):
if save_txt or save_img:
s = f"\n{len(list(save_dir.glob('labels/*.txt')))} labels saved to {save_dir / 'labels'}" if save_txt else ''
# print(f"Results saved to {save_dir}{s}")
if save_txt:
write_results(save_dir / 'labels' / 'result.txt', final_results)

print(f'Done. ({time.time() - t0:.3f}s)')

Expand Down