glenn-jocher commited on
Commit
86f4247
1 Parent(s): 0bb4395

Hybrid auto-labelling support (#1646)

Browse files
Files changed (1) hide show
  1. test.py +6 -4
test.py CHANGED
@@ -33,7 +33,8 @@ def test(data,
33
  dataloader=None,
34
  save_dir=Path(''), # for saving images
35
  save_txt=False, # for auto-labelling
36
- save_conf=False,
 
37
  plots=True,
38
  log_imgs=0): # number of logged images
39
 
@@ -45,7 +46,6 @@ def test(data,
45
  else: # called directly
46
  set_logging()
47
  device = select_device(opt.device, batch_size=batch_size)
48
- save_txt = opt.save_txt # save *.txt labels
49
 
50
  # Directories
51
  save_dir = Path(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok)) # increment run
@@ -115,7 +115,7 @@ def test(data,
115
 
116
  # Run NMS
117
  targets[:, 2:] *= torch.Tensor([width, height, width, height]).to(device) # to pixels
118
- lb = [targets[targets[:, 0] == i, 1:] for i in range(nb)] if save_txt else [] # for autolabelling
119
  t = time_synchronized()
120
  output = non_max_suppression(inf_out, conf_thres=conf_thres, iou_thres=iou_thres, labels=lb)
121
  t1 += time_synchronized() - t
@@ -292,6 +292,7 @@ if __name__ == '__main__':
292
  parser.add_argument('--augment', action='store_true', help='augmented inference')
293
  parser.add_argument('--verbose', action='store_true', help='report mAP by class')
294
  parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
 
295
  parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels')
296
  parser.add_argument('--save-json', action='store_true', help='save a cocoapi-compatible JSON results file')
297
  parser.add_argument('--project', default='runs/test', help='save to project/name')
@@ -313,7 +314,8 @@ if __name__ == '__main__':
313
  opt.single_cls,
314
  opt.augment,
315
  opt.verbose,
316
- save_txt=opt.save_txt,
 
317
  save_conf=opt.save_conf,
318
  )
319
 
 
33
  dataloader=None,
34
  save_dir=Path(''), # for saving images
35
  save_txt=False, # for auto-labelling
36
+ save_hybrid=False, # for hybrid auto-labelling
37
+ save_conf=False, # save auto-label confidences
38
  plots=True,
39
  log_imgs=0): # number of logged images
40
 
 
46
  else: # called directly
47
  set_logging()
48
  device = select_device(opt.device, batch_size=batch_size)
 
49
 
50
  # Directories
51
  save_dir = Path(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok)) # increment run
 
115
 
116
  # Run NMS
117
  targets[:, 2:] *= torch.Tensor([width, height, width, height]).to(device) # to pixels
118
+ lb = [targets[targets[:, 0] == i, 1:] for i in range(nb)] if save_hybrid else [] # for autolabelling
119
  t = time_synchronized()
120
  output = non_max_suppression(inf_out, conf_thres=conf_thres, iou_thres=iou_thres, labels=lb)
121
  t1 += time_synchronized() - t
 
292
  parser.add_argument('--augment', action='store_true', help='augmented inference')
293
  parser.add_argument('--verbose', action='store_true', help='report mAP by class')
294
  parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
295
+ parser.add_argument('--save-hybrid', action='store_true', help='save label+prediction hybrid results to *.txt')
296
  parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels')
297
  parser.add_argument('--save-json', action='store_true', help='save a cocoapi-compatible JSON results file')
298
  parser.add_argument('--project', default='runs/test', help='save to project/name')
 
314
  opt.single_cls,
315
  opt.augment,
316
  opt.verbose,
317
+ save_txt=opt.save_txt | opt.save_hybrid,
318
+ save_hybrid=opt.save_hybrid,
319
  save_conf=opt.save_conf,
320
  )
321