weida wang glenn-jocher commited on
Commit
04081f8
1 Parent(s): ce3872f

Trailing --save-txt whitespace bug fix (#1374)

Browse files

* update Write results

* Update detect.py

* Update test.py

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>

Files changed (2) hide show
  1. detect.py +1 -1
  2. test.py +1 -1
detect.py CHANGED
@@ -107,7 +107,7 @@ def detect(save_img=False):
107
  xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
108
  line = (cls, *xywh, conf) if opt.save_conf else (cls, *xywh) # label format
109
  with open(txt_path + '.txt', 'a') as f:
110
- f.write(('%g ' * len(line) + '\n') % line)
111
 
112
  if save_img or view_img: # Add bbox to image
113
  label = '%s %.2f' % (names[int(cls)], conf)
 
107
  xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
108
  line = (cls, *xywh, conf) if opt.save_conf else (cls, *xywh) # label format
109
  with open(txt_path + '.txt', 'a') as f:
110
+ f.write(('%g ' * len(line)).rstrip() % line + '\n')
111
 
112
  if save_img or view_img: # Add bbox to image
113
  label = '%s %.2f' % (names[int(cls)], conf)
test.py CHANGED
@@ -140,7 +140,7 @@ def test(data,
140
  xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
141
  line = (cls, *xywh, conf) if save_conf else (cls, *xywh) # label format
142
  with open(str(save_dir / 'labels' / Path(paths[si]).stem) + '.txt', 'a') as f:
143
- f.write(('%g ' * len(line) + '\n') % line)
144
 
145
  # W&B logging
146
  if len(wandb_images) < log_imgs:
 
140
  xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
141
  line = (cls, *xywh, conf) if save_conf else (cls, *xywh) # label format
142
  with open(str(save_dir / 'labels' / Path(paths[si]).stem) + '.txt', 'a') as f:
143
+ f.write(('%g ' * len(line)).rstrip() % line + '\n')
144
 
145
  # W&B logging
146
  if len(wandb_images) < log_imgs: