Diego Montes glenn-jocher commited on
Commit
2c63175
1 Parent(s): a42af30

Add nms and agnostic nms to export.py (#5938)

Browse files

* add nms and agnostic nms to export.py

* fix agnostic implies nms

* reorder args to group TF args

* PEP8 120 char

Co-authored-by: Glenn Jocher <[email protected]>

Files changed (1) hide show
  1. export.py +7 -3
export.py CHANGED
@@ -328,6 +328,8 @@ def run(data=ROOT / 'data/coco128.yaml', # 'dataset.yaml path'
328
  opset=14, # ONNX: opset version
329
  verbose=False, # TensorRT: verbose log
330
  workspace=4, # TensorRT: workspace size (GB)
 
 
331
  topk_per_class=100, # TF.js NMS: topk per class to keep
332
  topk_all=100, # TF.js NMS: topk for all classes to keep
333
  iou_thres=0.45, # TF.js NMS: IoU threshold
@@ -381,9 +383,9 @@ def run(data=ROOT / 'data/coco128.yaml', # 'dataset.yaml path'
381
  if any(tf_exports):
382
  pb, tflite, tfjs = tf_exports[1:]
383
  assert not (tflite and tfjs), 'TFLite and TF.js models must be exported separately, please pass only one type.'
384
- model = export_saved_model(model, im, file, dynamic, tf_nms=tfjs, agnostic_nms=tfjs,
385
- topk_per_class=topk_per_class, topk_all=topk_all, conf_thres=conf_thres,
386
- iou_thres=iou_thres) # keras model
387
  if pb or tfjs: # pb prerequisite to tfjs
388
  export_pb(model, im, file)
389
  if tflite:
@@ -414,6 +416,8 @@ def parse_opt():
414
  parser.add_argument('--opset', type=int, default=14, help='ONNX: opset version')
415
  parser.add_argument('--verbose', action='store_true', help='TensorRT: verbose log')
416
  parser.add_argument('--workspace', type=int, default=4, help='TensorRT: workspace size (GB)')
 
 
417
  parser.add_argument('--topk-per-class', type=int, default=100, help='TF.js NMS: topk per class to keep')
418
  parser.add_argument('--topk-all', type=int, default=100, help='TF.js NMS: topk for all classes to keep')
419
  parser.add_argument('--iou-thres', type=float, default=0.45, help='TF.js NMS: IoU threshold')
 
328
  opset=14, # ONNX: opset version
329
  verbose=False, # TensorRT: verbose log
330
  workspace=4, # TensorRT: workspace size (GB)
331
+ nms=False, # TF: add NMS to model
332
+ agnostic_nms=False, # TF: add agnostic NMS to model
333
  topk_per_class=100, # TF.js NMS: topk per class to keep
334
  topk_all=100, # TF.js NMS: topk for all classes to keep
335
  iou_thres=0.45, # TF.js NMS: IoU threshold
 
383
  if any(tf_exports):
384
  pb, tflite, tfjs = tf_exports[1:]
385
  assert not (tflite and tfjs), 'TFLite and TF.js models must be exported separately, please pass only one type.'
386
+ model = export_saved_model(model, im, file, dynamic, tf_nms=nms or agnostic_nms or tfjs,
387
+ agnostic_nms=agnostic_nms or tfjs, topk_per_class=topk_per_class, topk_all=topk_all,
388
+ conf_thres=conf_thres, iou_thres=iou_thres) # keras model
389
  if pb or tfjs: # pb prerequisite to tfjs
390
  export_pb(model, im, file)
391
  if tflite:
 
416
  parser.add_argument('--opset', type=int, default=14, help='ONNX: opset version')
417
  parser.add_argument('--verbose', action='store_true', help='TensorRT: verbose log')
418
  parser.add_argument('--workspace', type=int, default=4, help='TensorRT: workspace size (GB)')
419
+ parser.add_argument('--nms', action='store_true', help='TF: add NMS to model')
420
+ parser.add_argument('--agnostic-nms', action='store_true', help='TF: add agnostic NMS to model')
421
  parser.add_argument('--topk-per-class', type=int, default=100, help='TF.js NMS: topk per class to keep')
422
  parser.add_argument('--topk-all', type=int, default=100, help='TF.js NMS: topk for all classes to keep')
423
  parser.add_argument('--iou-thres', type=float, default=0.45, help='TF.js NMS: IoU threshold')