Describe the bug
It is not possible to export the trained model to onnx format. My model is a fasterRCNN, trained using PyTroch Lightning. After
light_model.to_onnx("model_lightnining_export.onnx",
batch[0],
export_params=True,)
input_names = ['input'],
output_names = ['output'],
dynamic_axes={'input' : {0 : 'batch_size'},'output' : {0 : 'batch_size'}})
The method crushes
RuntimeError: Failed to export an ONNX attribute 'onnx::Sub', since it's not constant, please try to make things (e.g., kernel size) static if possible
To Reproduce
1.Train the model
trainer = Trainer(max_epochs=10,
checkpoint_callback=False,
logger=False,
gpus=0,
resume_from_checkpoint = '/home/piotr/Downloads/epoch=4(1).ckpt'
)
trainer.fit(light_model, dm)
i = 0
samples = [valid_ds[i] for i in range(i, i+2)]
batch, samples = faster_rcnn.build_infer_batch(samples)
ONNX formatlight_model.to_onnx("model_lightnining_export.onnx",
batch[0],
export_params=True,)
input_names = ['input'],
output_names = ['output'],
dynamic_axes={'input' : {0 : 'batch_size'},'output' : {0 : 'batch_size'}})
Expected behavior
The model saved successfully as ONNX
Desktop (please complete the following information):
Okk, nevermind, I have found the solution. The error was due to the resnet, not due to the icevision. I had to change opset_version, to 11
light_model.to_onnx("model_lightnining_export.onnx",
batch[0],
export_params=True,
opset_version=11,
input_names = ['input'],
output_names = ['output'],
dynamic_axes={'input' : {0 : 'batch_size'},'output' : {0 : 'batch_size'}})
Thank you @tugot17 for sharing the solution that you found. This will help other who might face a similar issue.
Most helpful comment
Okk, nevermind, I have found the solution. The error was due to the resnet, not due to the icevision. I had to change
opset_version, to 11