From adbaa859e43998b5b73859af2f9ecdd66b4a07f2 Mon Sep 17 00:00:00 2001 From: Ashafix Date: Tue, 30 Mar 2021 23:30:48 +0200 Subject: [PATCH 1/7] command line option for line thickness and hiding labels --- detect.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/detect.py b/detect.py index 2a4d6f4550c8..f8b27cf53f4e 100644 --- a/detect.py +++ b/detect.py @@ -101,6 +101,7 @@ def detect(save_img=False): s += f"{n} {names[int(c)]}{'s' * (n > 1)}, " # add to string # Write results + label = None for *xyxy, conf, cls in reversed(det): if save_txt: # Write to file xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh @@ -109,8 +110,9 @@ def detect(save_img=False): f.write(('%g ' * len(line)).rstrip() % line + '\n') if save_img or view_img: # Add bbox to image - label = f'{names[int(cls)]} {conf:.2f}' - plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=3) + if not opt.hide_labels: + label = f'{names[int(cls)]} {conf:.2f}' + plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=opt.line_thickness) # Print time (inference + NMS) print(f'{s}Done. ({t2 - t1:.3f}s)') @@ -165,6 +167,8 @@ def detect(save_img=False): parser.add_argument('--project', default='runs/detect', help='save results to project/name') parser.add_argument('--name', default='exp', help='save results to project/name') parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') + parser.add_argument('--line-thickness', default=3, type=int, help='thickness of the bounding boxes') + parser.add_argument('--hide-labels', default=False, action='store_true', help='hide class labels on bounding boxes') opt = parser.parse_args() print(opt) check_requirements(exclude=('pycocotools', 'thop')) From 218e45817b644e96286f2caf955589d1d61a3310 Mon Sep 17 00:00:00 2001 From: Ashafix Date: Fri, 23 Apr 2021 16:58:42 +0200 Subject: [PATCH 2/7] command line option for line thickness and hiding labels --- detect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detect.py b/detect.py index f8b27cf53f4e..2fbc269d60fc 100644 --- a/detect.py +++ b/detect.py @@ -109,7 +109,7 @@ def detect(save_img=False): with open(txt_path + '.txt', 'a') as f: f.write(('%g ' * len(line)).rstrip() % line + '\n') - if save_img or view_img: # Add bbox to image + if save_img or opt.save_crop or view_img: # Add bbox to image if not opt.hide_labels: label = f'{names[int(cls)]} {conf:.2f}' plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=opt.line_thickness) From e486e9f81e4fde3533eba96569ef612d23fc4764 Mon Sep 17 00:00:00 2001 From: Ashafix Date: Fri, 23 Apr 2021 17:00:28 +0200 Subject: [PATCH 3/7] command line option for line thickness and hiding labels --- detect.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/detect.py b/detect.py index 2fbc269d60fc..3a1fa26cde47 100644 --- a/detect.py +++ b/detect.py @@ -110,9 +110,10 @@ def detect(save_img=False): f.write(('%g ' * len(line)).rstrip() % line + '\n') if save_img or opt.save_crop or view_img: # Add bbox to image + c = int(cls) # integer class if not opt.hide_labels: - label = f'{names[int(cls)]} {conf:.2f}' - plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=opt.line_thickness) + label = f'{names[c]} {conf:.2f}' + plot_one_box(xyxy, im0, label=label, color=colors[c], line_thickness=opt.line_thickness) # Print time (inference + NMS) print(f'{s}Done. ({t2 - t1:.3f}s)') From da418e7ce80b8d958464b8eee5ca33b9cf9f4c7e Mon Sep 17 00:00:00 2001 From: Ashafix Date: Fri, 23 Apr 2021 17:02:39 +0200 Subject: [PATCH 4/7] command line option for line thickness and hiding labels --- detect.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/detect.py b/detect.py index 3a1fa26cde47..d598edb7f527 100644 --- a/detect.py +++ b/detect.py @@ -114,6 +114,8 @@ def detect(save_img=False): if not opt.hide_labels: label = f'{names[c]} {conf:.2f}' plot_one_box(xyxy, im0, label=label, color=colors[c], line_thickness=opt.line_thickness) + if opt.save_crop: + save_one_box(xyxy, im0s, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True) # Print time (inference + NMS) print(f'{s}Done. ({t2 - t1:.3f}s)') From 16ceec63119b6438711a44039cc3f6f99fd764c8 Mon Sep 17 00:00:00 2001 From: Ashafix Date: Fri, 23 Apr 2021 17:06:35 +0200 Subject: [PATCH 5/7] command line option for line thickness and hiding labels --- detect.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/detect.py b/detect.py index 2a4d6f4550c8..d598edb7f527 100644 --- a/detect.py +++ b/detect.py @@ -101,6 +101,7 @@ def detect(save_img=False): s += f"{n} {names[int(c)]}{'s' * (n > 1)}, " # add to string # Write results + label = None for *xyxy, conf, cls in reversed(det): if save_txt: # Write to file xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh @@ -108,9 +109,13 @@ def detect(save_img=False): with open(txt_path + '.txt', 'a') as f: f.write(('%g ' * len(line)).rstrip() % line + '\n') - if save_img or view_img: # Add bbox to image - label = f'{names[int(cls)]} {conf:.2f}' - plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=3) + if save_img or opt.save_crop or view_img: # Add bbox to image + c = int(cls) # integer class + if not opt.hide_labels: + label = f'{names[c]} {conf:.2f}' + plot_one_box(xyxy, im0, label=label, color=colors[c], line_thickness=opt.line_thickness) + if opt.save_crop: + save_one_box(xyxy, im0s, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True) # Print time (inference + NMS) print(f'{s}Done. ({t2 - t1:.3f}s)') @@ -165,6 +170,8 @@ def detect(save_img=False): parser.add_argument('--project', default='runs/detect', help='save results to project/name') parser.add_argument('--name', default='exp', help='save results to project/name') parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') + parser.add_argument('--line-thickness', default=3, type=int, help='thickness of the bounding boxes') + parser.add_argument('--hide-labels', default=False, action='store_true', help='hide class labels on bounding boxes') opt = parser.parse_args() print(opt) check_requirements(exclude=('pycocotools', 'thop')) From 17322364bf795389aacea9de52aa2e28146c557b Mon Sep 17 00:00:00 2001 From: Ashafix Date: Fri, 23 Apr 2021 17:11:38 +0200 Subject: [PATCH 6/7] command line option for hiding confidence values --- detect.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/detect.py b/detect.py index d598edb7f527..502d7a052204 100644 --- a/detect.py +++ b/detect.py @@ -112,7 +112,11 @@ def detect(save_img=False): if save_img or opt.save_crop or view_img: # Add bbox to image c = int(cls) # integer class if not opt.hide_labels: - label = f'{names[c]} {conf:.2f}' + if opt.hide_values: + label = names[c] + else: + label = f'{names[c]} {conf:.2f}' + plot_one_box(xyxy, im0, label=label, color=colors[c], line_thickness=opt.line_thickness) if opt.save_crop: save_one_box(xyxy, im0s, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True) @@ -172,6 +176,7 @@ def detect(save_img=False): parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') parser.add_argument('--line-thickness', default=3, type=int, help='thickness of the bounding boxes') parser.add_argument('--hide-labels', default=False, action='store_true', help='hide class labels on bounding boxes') + parser.add_argument('--hide-values', default=False, action='store_true', help='hide confidence values on bounding boxes') opt = parser.parse_args() print(opt) check_requirements(exclude=('pycocotools', 'thop')) From c31e59d6eb2906f79ae205c57471e8880d0b5226 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 23 Apr 2021 21:02:21 +0200 Subject: [PATCH 7/7] Update detect.py --- detect.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/detect.py b/detect.py index 043ac8b36a0a..358ef9e3eb1c 100644 --- a/detect.py +++ b/detect.py @@ -101,7 +101,6 @@ def detect(opt): s += f"{n} {names[int(c)]}{'s' * (n > 1)}, " # add to string # Write results - label = None for *xyxy, conf, cls in reversed(det): if save_txt: # Write to file xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh @@ -111,11 +110,7 @@ def detect(opt): if save_img or opt.save_crop or view_img: # Add bbox to image c = int(cls) # integer class - if not opt.hide_labels: - if opt.hide_values: - label = names[c] - else: - label = f'{names[c]} {conf:.2f}' + label = None if opt.hide_labels else (names[c] if opt.hide_conf else f'{names[c]} {conf:.2f}') plot_one_box(xyxy, im0, label=label, color=colors[c], line_thickness=opt.line_thickness) if opt.save_crop: @@ -175,9 +170,9 @@ def detect(opt): parser.add_argument('--project', default='runs/detect', help='save results to project/name') parser.add_argument('--name', default='exp', help='save results to project/name') parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') - parser.add_argument('--line-thickness', default=3, type=int, help='thickness of the bounding boxes') - parser.add_argument('--hide-labels', default=False, action='store_true', help='hide class labels on bounding boxes') - parser.add_argument('--hide-values', default=False, action='store_true', help='hide confidence values on bounding boxes') + parser.add_argument('--line-thickness', default=3, type=int, help='bounding box thickness (pixels)') + parser.add_argument('--hide-labels', default=True, action='store_true', help='hide labels') + parser.add_argument('--hide-conf', default=True, action='store_true', help='hide confidences') opt = parser.parse_args() print(opt) check_requirements(exclude=('pycocotools', 'thop'))