Proper way to export the model to onnx
See original GitHub issueimport torchreid
torchreid.models.show_avai_models()
model = torchreid.models.build_model(name='osnet_ain_x1_0', num_classes=1000)
torchreid.utils.load_pretrained_weights(model, "osnet_ain_x1_0_msmt17_256x128_amsgrad_ep50_lr0.0015_coslr_b64_fb10_softmax_labsmth_flip_jitter.pth")
from torch.autograd import Variable
import torch
import onnx
input_name = ['input']
output_name = ['output']
input = Variable(torch.randn(1, 3, 256, 128))
torch.onnx.export(model, input, 'osnet_ain_x1_0.onnx', input_names=input_name,output_names=output_name, verbose=True, export_params=True)
The model after convert only 10633KBytes, while the pytorch model got 16888KBytes
onnx_model = onnx.load("osnet_ain_x1_0.onnx")
onnx.checker.check_model(onnx_model)
- The output messages seems all fine, but is this the correct way?
- What is the num_classes I should set?
- Am I using correct input_name and output_name
Model before convert is 16888KB, model after convert only got 10633KB
Issue Analytics
- State:
- Created 4 years ago
- Comments:19 (2 by maintainers)
Top Results From Across the Web
(optional) Exporting a Model from PyTorch to ONNX and ...
To export a model, we call the torch.onnx.export() function. This will execute the model, recording a trace of what operators are used to...
Read more >How to Convert a PyTorch Model to ONNX in 5 Minutes - Deci AI
Converting deep learning models from PyTorch to ONNX is quite straightforward. Start by loading a pre-trained ResNet-50 model from PyTorch's ...
Read more >Tutorial 5: Exporting a model to ONNX
We provide a python script to export the pytorch model trained by MMPose to ONNX. python tools/deployment/pytorch2onnx.py ${CONFIG_FILE} ${CHECKPOINT_FILE} ...
Read more >Best Practices for Neural Network Exports to ONNX
Our experience shows that is easier to export PyTorch models. If possible, choose a PyTorch source and convert it using the built-in torch.onnx...
Read more >Export to ONNX - Transformers - Hugging Face
In this guide, we'll show you how to export Transformers models to ONNX ... all values close (atol: 1e-05) All good, model saved...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have a working multibackend (ONNX, OpenVINO and TFLite) class for for the ReID models that I manged to export (
mobilenet
,resnet50
andosnet
models) with my export script. My export pipeline is as follows: PT --> ONNX --> OpenVINO --> TFLite.osnet
models fails in the OpenVINO export;mobilenet
andresnet50
models go all the way through. Feel free to experiment with it, it is in working condition as shown by my CI pipeline. Don’t forget to drop a PR if you have any improvements! 😄At last I got the output, need to print it out manually, since it is too long I put it at pastebin.
This time I test it with the output value.
But, assertion raise
ps : Export the model by
torch.jit.trace(model, example)
work, figure out how to get 512 features.