Cristi Fati commited on
Commit
9ab561d
1 Parent(s): be86c21

Parameterize ONNX `--opset-version` (#3154)

Browse files
Files changed (1) hide show
  1. models/export.py +2 -1
models/export.py CHANGED
@@ -34,6 +34,7 @@ if __name__ == '__main__':
34
  parser.add_argument('--optimize', action='store_true', help='optimize TorchScript for mobile') # TorchScript-only
35
  parser.add_argument('--dynamic', action='store_true', help='dynamic ONNX axes') # ONNX-only
36
  parser.add_argument('--simplify', action='store_true', help='simplify ONNX model') # ONNX-only
 
37
  opt = parser.parse_args()
38
  opt.img_size *= 2 if len(opt.img_size) == 1 else 1 # expand
39
  opt.include = [x.lower() for x in opt.include]
@@ -95,7 +96,7 @@ if __name__ == '__main__':
95
 
96
  print(f'{prefix} starting export with onnx {onnx.__version__}...')
97
  f = opt.weights.replace('.pt', '.onnx') # filename
98
- torch.onnx.export(model, img, f, verbose=False, opset_version=12, input_names=['images'],
99
  dynamic_axes={'images': {0: 'batch', 2: 'height', 3: 'width'}, # size(1,3,640,640)
100
  'output': {0: 'batch', 2: 'y', 3: 'x'}} if opt.dynamic else None)
101
 
 
34
  parser.add_argument('--optimize', action='store_true', help='optimize TorchScript for mobile') # TorchScript-only
35
  parser.add_argument('--dynamic', action='store_true', help='dynamic ONNX axes') # ONNX-only
36
  parser.add_argument('--simplify', action='store_true', help='simplify ONNX model') # ONNX-only
37
+ parser.add_argument('--opset-version', type=int, default=12, help='ONNX opset version') # ONNX-only
38
  opt = parser.parse_args()
39
  opt.img_size *= 2 if len(opt.img_size) == 1 else 1 # expand
40
  opt.include = [x.lower() for x in opt.include]
 
96
 
97
  print(f'{prefix} starting export with onnx {onnx.__version__}...')
98
  f = opt.weights.replace('.pt', '.onnx') # filename
99
+ torch.onnx.export(model, img, f, verbose=False, opset_version=opt.opset_version, input_names=['images'],
100
  dynamic_axes={'images': {0: 'batch', 2: 'height', 3: 'width'}, # size(1,3,640,640)
101
  'output': {0: 'batch', 2: 'y', 3: 'x'}} if opt.dynamic else None)
102