Skip to content

Commit

Permalink
added feature to save conf in txt labels
Browse files Browse the repository at this point in the history
  • Loading branch information
oakhtar147 committed Sep 18, 2020
1 parent e37f51d commit bc16152
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@


def detect(save_img=False):
out, source, weights, view_img, save_txt, imgsz = \
opt.output, opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size
out, source, weights, view_img, save_txt, imgsz, save_conf = \
opt.output, opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size, opt.save_conf
webcam = source.isnumeric() or source.startswith('rtsp') or source.startswith('http') or source.endswith('.txt')

# Initialize
Expand Down Expand Up @@ -106,7 +106,10 @@ def detect(save_img=False):
if save_txt: # Write to file
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
with open(txt_path + '.txt', 'a') as f:
f.write(('%g ' * 5 + '\n') % (cls, *xywh)) # label format
if save_conf:
f.write(('%g ' * 6 + '\n') % (cls, conf, *xywh)) # label format includes conf
else:
f.write(('%g ' * 5 + '\n') % (cls, *xywh)) # label format does not include conf

if save_img or view_img: # Add bbox to image
label = '%s %.2f' % (names[int(cls)], conf)
Expand Down Expand Up @@ -161,6 +164,7 @@ def detect(save_img=False):
parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
parser.add_argument('--augment', action='store_true', help='augmented inference')
parser.add_argument('--update', action='store_true', help='update all models')
parser.add_argument('--save-conf', action='store_true', help='put confidence score next to class in label*.txt')
opt = parser.parse_args()
print(opt)

Expand Down

0 comments on commit bc16152

Please sign in to comment.