Skip to content

Commit

Permalink
Parameterize ONNX --opset-version (ultralytics#3154)
Browse files Browse the repository at this point in the history
  • Loading branch information
CristiFati authored May 16, 2021
1 parent 6ba7dca commit b18ef0d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion models/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
parser.add_argument('--optimize', action='store_true', help='optimize TorchScript for mobile') # TorchScript-only
parser.add_argument('--dynamic', action='store_true', help='dynamic ONNX axes') # ONNX-only
parser.add_argument('--simplify', action='store_true', help='simplify ONNX model') # ONNX-only
parser.add_argument('--opset-version', type=int, default=12, help='ONNX opset version') # ONNX-only
opt = parser.parse_args()
opt.img_size *= 2 if len(opt.img_size) == 1 else 1 # expand
opt.include = [x.lower() for x in opt.include]
Expand Down Expand Up @@ -95,7 +96,7 @@

print(f'{prefix} starting export with onnx {onnx.__version__}...')
f = opt.weights.replace('.pt', '.onnx') # filename
torch.onnx.export(model, img, f, verbose=False, opset_version=12, input_names=['images'],
torch.onnx.export(model, img, f, verbose=False, opset_version=opt.opset_version, input_names=['images'],
dynamic_axes={'images': {0: 'batch', 2: 'height', 3: 'width'}, # size(1,3,640,640)
'output': {0: 'batch', 2: 'y', 3: 'x'}} if opt.dynamic else None)

Expand Down

0 comments on commit b18ef0d

Please sign in to comment.