Add confidence score to label txt files (#994)
Browse files* add contrast to conf/class against bbox rectangle color
* added feature to save conf in txt labels
* Update general.py
* Update detect.py
* Update detect.py
* Update detect.py
save_conf variable removed as only used once, so we can use opt.save_conf instead.
* Update detect.py
* Update detect.py
Co-authored-by: Glenn Jocher <[email protected]>
detect.py
CHANGED
@@ -104,8 +104,9 @@ def detect(save_img=False):
|
|
104 |
for *xyxy, conf, cls in reversed(det):
|
105 |
if save_txt: # Write to file
|
106 |
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
|
|
|
107 |
with open(txt_path + '.txt', 'a') as f:
|
108 |
-
f.write(('%g ' *
|
109 |
|
110 |
if save_img or view_img: # Add bbox to image
|
111 |
label = '%s %.2f' % (names[int(cls)], conf)
|
@@ -154,6 +155,7 @@ if __name__ == '__main__':
|
|
154 |
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
|
155 |
parser.add_argument('--view-img', action='store_true', help='display results')
|
156 |
parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
|
|
|
157 |
parser.add_argument('--classes', nargs='+', type=int, help='filter by class: --class 0, or --class 0 2 3')
|
158 |
parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
|
159 |
parser.add_argument('--augment', action='store_true', help='augmented inference')
|
|
|
104 |
for *xyxy, conf, cls in reversed(det):
|
105 |
if save_txt: # Write to file
|
106 |
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
|
107 |
+
line = (cls, conf, *xywh) if opt.save_conf else (cls, *xywh) # label format
|
108 |
with open(txt_path + '.txt', 'a') as f:
|
109 |
+
f.write(('%g ' * len(line) + '\n') % line)
|
110 |
|
111 |
if save_img or view_img: # Add bbox to image
|
112 |
label = '%s %.2f' % (names[int(cls)], conf)
|
|
|
155 |
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
|
156 |
parser.add_argument('--view-img', action='store_true', help='display results')
|
157 |
parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
|
158 |
+
parser.add_argument('--save-conf', action='store_true', help='output confidences in --save-txt labels')
|
159 |
parser.add_argument('--classes', nargs='+', type=int, help='filter by class: --class 0, or --class 0 2 3')
|
160 |
parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
|
161 |
parser.add_argument('--augment', action='store_true', help='augmented inference')
|