glenn-jocher commited on
Commit
97b5186
·
unverified ·
2 Parent(s): 256a3e8 8c5b622

Merge pull request #206 from ml5ah/utils-fix

Browse files
Files changed (1) hide show
  1. detect.py +3 -2
detect.py CHANGED
@@ -80,6 +80,7 @@ def detect(save_img=False):
80
  p, s, im0 = path, '', im0s
81
 
82
  save_path = str(Path(out) / Path(p).name)
 
83
  s += '%gx%g ' % img.shape[2:] # print string
84
  gn = torch.tensor(im0.shape)[[1, 0, 1, 0]] #  normalization gain whwh
85
  if det is not None and len(det):
@@ -95,8 +96,8 @@ def detect(save_img=False):
95
  for *xyxy, conf, cls in det:
96
  if save_txt: # Write to file
97
  xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
98
- with open(save_path[:save_path.rfind('.')] + '.txt', 'a') as file:
99
- file.write(('%g ' * 5 + '\n') % (cls, *xywh)) # label format
100
 
101
  if save_img or view_img: # Add bbox to image
102
  label = '%s %.2f' % (names[int(cls)], conf)
 
80
  p, s, im0 = path, '', im0s
81
 
82
  save_path = str(Path(out) / Path(p).name)
83
+ txt_path = str(Path(out) / Path(p).stem) + ('_%g' % dataset.frame if dataset.mode == 'video' else '')
84
  s += '%gx%g ' % img.shape[2:] # print string
85
  gn = torch.tensor(im0.shape)[[1, 0, 1, 0]] #  normalization gain whwh
86
  if det is not None and len(det):
 
96
  for *xyxy, conf, cls in det:
97
  if save_txt: # Write to file
98
  xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
99
+ with open(txt_path + '.txt', 'a') as f:
100
+ f.write(('%g ' * 5 + '\n') % (cls, *xywh)) # label format
101
 
102
  if save_img or view_img: # Add bbox to image
103
  label = '%s %.2f' % (names[int(cls)], conf)