commit
97b5186fa0
|
@ -80,6 +80,7 @@ def detect(save_img=False):
|
|||
p, s, im0 = path, '', im0s
|
||||
|
||||
save_path = str(Path(out) / Path(p).name)
|
||||
txt_path = str(Path(out) / Path(p).stem) + ('_%g' % dataset.frame if dataset.mode == 'video' else '')
|
||||
s += '%gx%g ' % img.shape[2:] # print string
|
||||
gn = torch.tensor(im0.shape)[[1, 0, 1, 0]] # normalization gain whwh
|
||||
if det is not None and len(det):
|
||||
|
@ -95,8 +96,8 @@ def detect(save_img=False):
|
|||
for *xyxy, conf, cls in det:
|
||||
if save_txt: # Write to file
|
||||
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
|
||||
with open(save_path[:save_path.rfind('.')] + '.txt', 'a') as file:
|
||||
file.write(('%g ' * 5 + '\n') % (cls, *xywh)) # label format
|
||||
with open(txt_path + '.txt', 'a') as f:
|
||||
f.write(('%g ' * 5 + '\n') % (cls, *xywh)) # label format
|
||||
|
||||
if save_img or view_img: # Add bbox to image
|
||||
label = '%s %.2f' % (names[int(cls)], conf)
|
||||
|
|
Loading…
Reference in New Issue