|
|
@@ -22,6 +22,7 @@ if __name__ == '__main__': |
|
|
|
parser = argparse.ArgumentParser() |
|
|
|
parser.add_argument('--weights', type=str, default='./yolov5s.pt', help='weights path') # from yolov5/models/ |
|
|
|
parser.add_argument('--img-size', nargs='+', type=int, default=[640, 640], help='image size') # height, width |
|
|
|
parser.add_argument('--dynamic', action='store_true', help='dynamic ONNX axes') |
|
|
|
parser.add_argument('--batch-size', type=int, default=1, help='batch size') |
|
|
|
opt = parser.parse_args() |
|
|
|
opt.img_size *= 2 if len(opt.img_size) == 1 else 1 # expand |
|
|
@@ -70,7 +71,9 @@ if __name__ == '__main__': |
|
|
|
print('\nStarting ONNX export with onnx %s...' % onnx.__version__) |
|
|
|
f = opt.weights.replace('.pt', '.onnx') # filename |
|
|
|
torch.onnx.export(model, img, f, verbose=False, opset_version=12, input_names=['images'], |
|
|
|
output_names=['classes', 'boxes'] if y is None else ['output']) |
|
|
|
output_names=['classes', 'boxes'] if y is None else ['output'], |
|
|
|
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) |
|
|
|
|
|
|
|
# Checks |
|
|
|
onnx_model = onnx.load(f) # load onnx model |