ONNX object from PyTorch model without exporting

542 Views Asked by At

Is it possible to convert the PyTorch Model to ONNX without exporting and further use it as an ONNX object directly in the script.

1

There are 1 best solutions below

0
On

You can export to memory, something like this:

import io
f = io.BytesIO()
torch.onnx.export(model, sample_inputs, f, ...)
onnx_model = onnx.load_model_from_string(f.getvalue())