From 464025b7684c82a0c01d68dcccbd402f1581b486 Mon Sep 17 00:00:00 2001 From: Tigran Nalbandyan Date: Mon, 28 Nov 2022 18:26:45 +0400 Subject: [PATCH 1/3] Added file output from --save-txt in yolov7 demo #32. --- tools/mc_demo_yolov7.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/mc_demo_yolov7.py b/tools/mc_demo_yolov7.py index 0a3f0b3e..4d827a59 100644 --- a/tools/mc_demo_yolov7.py +++ b/tools/mc_demo_yolov7.py @@ -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 @@ -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)') @@ -183,6 +187,7 @@ def detect(save_img=False): vid_writer.write(im0) if save_txt or save_img: + write_results(save_dir / 'labels' / "result.txt", final_results) 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}") From 5d10993bea6d24126169b334708c5f324293cc30 Mon Sep 17 00:00:00 2001 From: Tigran Nalbandyan Date: Mon, 28 Nov 2022 18:33:11 +0400 Subject: [PATCH 2/3] Corrected the style. --- tools/mc_demo_yolov7.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/mc_demo_yolov7.py b/tools/mc_demo_yolov7.py index 4d827a59..6411e9e3 100644 --- a/tools/mc_demo_yolov7.py +++ b/tools/mc_demo_yolov7.py @@ -187,7 +187,7 @@ def detect(save_img=False): vid_writer.write(im0) if save_txt or save_img: - write_results(save_dir / 'labels' / "result.txt", final_results) + write_results(save_dir / 'labels' / 'result.txt', final_results) 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}") From c98557db638163b8a0ccd72cce7e4450a667eac8 Mon Sep 17 00:00:00 2001 From: Tigran Nalbandyan Date: Mon, 28 Nov 2022 19:13:30 +0400 Subject: [PATCH 3/3] Added an additional check for save_txt. --- tools/mc_demo_yolov7.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/mc_demo_yolov7.py b/tools/mc_demo_yolov7.py index 6411e9e3..7cf7eaae 100644 --- a/tools/mc_demo_yolov7.py +++ b/tools/mc_demo_yolov7.py @@ -187,9 +187,10 @@ def detect(save_img=False): vid_writer.write(im0) if save_txt or save_img: - write_results(save_dir / 'labels' / 'result.txt', final_results) 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)')