Skip to content

Unable to export model to onnx format #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 2 tasks
PranavDV-VCTI opened this issue Apr 2, 2025 · 13 comments
Open
1 of 2 tasks

Unable to export model to onnx format #101

PranavDV-VCTI opened this issue Apr 2, 2025 · 13 comments
Labels
bug Something isn't working exports Model exports (ONNX, TensorRT, TFLite, etc.)

Comments

@PranavDV-VCTI
Copy link

PranavDV-VCTI commented Apr 2, 2025

Search before asking

  • I have searched the RF-DETR issues and found no similar bug report.

Bug

from rfdetr import RFDETRBase
best_checkpoint = "/home/RF-DETR/output/checkpoint_best_ema.pth"
model = RFDETRBase(resolution=672, num_classes=1, pretrain_weights=best_checkpoint)
model.export()

When I execute the code, I don't encounter any errors, but the execution never completes, even after waiting for several hours. Instead, I only receive the following warnings:

Note: I face no issues when using model.predict()

Loading pretrain weights
num_classes mismatch: pretrain weights has 0 classes, but your model has 1 classes
reinitializing detection head with 0 classes
Exporting model to ONNX format
UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at /opt/conda/conda-bld/pytorch_1729647429097/work/aten/src/ATen/native/TensorShape.cpp:3595.)
PyTorch inference output shapes - Boxes: torch.Size([1, 3900, 4]), Labels: torch.Size([1, 3900, 1])
TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
TracerWarning: torch.as_tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).
TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
TracerWarning: Converting a tensor to a Python float might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).
TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).

Environment

RF-DETR 1.0.8
OS. Ubuntu 22.04
python 3.11.11

Minimal Reproducible Example

from rfdetr import RFDETRBase
best_checkpoint = "/home/RF-DETR/output/checkpoint_best_ema.pth"
model = RFDETRBase(resolution=672, num_classes=1, pretrain_weights=best_checkpoint)
model.export()

Additional

No response

Are you willing to submit a PR?

  • Yes, I'd like to help by submitting a PR!
@PranavDV-VCTI PranavDV-VCTI added the bug Something isn't working label Apr 2, 2025
@SkalskiP
Copy link
Collaborator

SkalskiP commented Apr 2, 2025

@isaacrob-roboflow any idea what's happening here?

@SkalskiP SkalskiP added the exports Model exports (ONNX, TensorRT, TFLite, etc.) label Apr 2, 2025
@isaacrob-roboflow
Copy link
Collaborator

Nothing comes to mind! Can you do a pip freeze and provide versions?

@PranavDV-VCTI
Copy link
Author

Sure @isaacrob-roboflow

absl-py==2.2.1
accelerate==1.4.0
albucore==0.0.23
albumentations==2.0.5
annotated-types==0.7.0
anyio==4.8.0
anywidget==0.9.18
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
arrow==1.3.0
asttokens==3.0.0
async-lru==2.0.4
attrs==25.2.0
babel==2.17.0
bbox_visualizer==0.2.0
beautifulsoup4==4.13.3
bleach==6.2.0
Brotli @ file:///croot/brotli-split_1736182456865/work
certifi @ file:///croot/certifi_1738623731865/work/certifi
cffi==1.17.1
charset-normalizer @ file:///croot/charset-normalizer_1721748349566/work
click==8.1.8
coloredlogs==15.0.1
comm==0.2.2
contourpy==1.3.1
cycler==0.12.1
Cython==3.0.12
dataclasses==0.6
debugpy==1.8.13
decorator==5.2.1
defusedxml==0.7.1
docker-pycreds==0.4.0
einops==0.8.1
executing==2.2.0
fairscale==0.4.13
fastjsonschema==2.21.1
filelock @ file:///croot/filelock_1700591183607/work
filetype==1.2.0
flatbuffers==25.2.10
fonttools==4.56.0
fqdn==1.5.1
fsspec==2025.3.0
ftfy==6.3.1
gitdb==4.0.12
GitPython==3.1.44
gmpy2 @ file:///croot/gmpy2_1738085463648/work
grpcio==1.71.0
h11==0.14.0
httpcore==1.0.7
httpx==0.28.1
huggingface-hub==0.29.2
humanfriendly==10.0
idna @ file:///croot/idna_1714398848350/work
ipykernel @ file:///croot/ipykernel_1737660677549/work
ipython==9.0.2
ipython_pygments_lexers==1.1.1
ipywidgets==8.1.5
isoduration==20.11.0
jedi==0.19.2
Jinja2 @ file:///croot/jinja2_1737760107953/work
joblib==1.4.2
json5==0.10.0
jsonpointer==3.0.0
jsonschema==4.23.0
jsonschema-specifications==2024.10.1
jupyter-events==0.12.0
jupyter-lsp==2.2.5
jupyter_bbox_widget==0.6.0
jupyter_client @ file:///croot/jupyter_client_1737570961872/work
jupyter_core @ file:///croot/jupyter_core_1718818295206/work
jupyter_server==2.15.0
jupyter_server_terminals==0.5.3
jupyterlab==4.3.5
jupyterlab_pygments==0.3.0
jupyterlab_server==2.27.3
jupyterlab_widgets==3.0.13
kiwisolver==1.4.8
lightning-utilities==0.14.0
Markdown==3.7
markdown-it-py==3.0.0
MarkupSafe @ file:///croot/markupsafe_1738584038848/work
matplotlib==3.10.1
matplotlib-inline==0.1.7
mdurl==0.1.2
mistune==3.1.2
mkl-service==2.4.0
mkl_fft @ file:///io/mkl313/mkl_fft_1730824109137/work
mkl_random @ file:///io/mkl313/mkl_random_1730823916628/work
mpmath @ file:///croot/mpmath_1690848262763/work
nbclient==0.10.2
nbconvert==7.16.6
nbformat==5.10.4
nest-asyncio==1.6.0
networkx @ file:///croot/networkx_1737039604450/work
ninja==1.11.1.4
notebook==7.3.2
notebook_shim==0.2.4
numpy @ file:///croot/numpy_and_numpy_base_1725470312869/work/dist/numpy-2.0.1-cp311-cp311-linux_x86_64.whl#sha256=372b9067cf9c96d8662c6f20ef49eeda43f0f8d2f074820224c954d8d8fae7bc
onnx==1.16.1
onnx-graphsurgeon==0.5.7
onnxruntime==1.21.0
onnxruntime-gpu==1.21.0
onnxsim==0.4.36
open_clip_torch==2.31.0
opencv-python==4.11.0.86
opencv-python-headless==4.10.0.84
overrides==7.7.0
packaging==24.2
pandas==2.2.3
pandocfilters==1.5.1
parso==0.8.4
peft==0.15.1
pexpect==4.9.0
pillow @ file:///croot/pillow_1738010226202/work
platformdirs==4.3.6
polygraphy==0.49.20
pprintpp==0.4.0
prometheus_client==0.21.1
prompt_toolkit==3.0.50
protobuf==5.29.3
psutil==7.0.0
psygnal==0.12.0
ptyprocess==0.7.0
pure_eval==0.2.3
pycocotools==2.0.8
pycparser==2.22
pydantic==2.10.6
pydantic_core==2.27.2
Pygments==2.19.1
pylabel==0.1.55
pyparsing==3.2.1
PySocks @ file:///work/ci_py311/pysocks_1676822712504/work
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
python-json-logger==3.3.0
pytz==2025.2
PyYAML @ file:///croot/pyyaml_1728657952215/work
pyzmq==26.3.0
referencing==0.36.2
regex==2024.11.6
requests @ file:///croot/requests_1730999120400/work
requests-toolbelt==1.0.0
rf100vl==1.0.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rfdetr==1.0.8
rich==14.0.0
roboflow==1.1.56
rpds-py==0.23.1
safetensors==0.5.3
scikit-learn==1.6.1
scipy==1.15.2
Send2Trash==1.8.3
sentry-sdk==2.22.0
setproctitle==1.3.5
simsimd==6.2.1
six==1.17.0
smmap==5.0.2
sniffio==1.3.1
soupsieve==2.6
stack-data==0.6.3
stringzilla==3.12.3
supervision==0.25.1
sympy==1.13.1
tensorboard==2.19.0
tensorboard-data-server==0.7.2
terminado==0.18.1
threadpoolctl==3.6.0
timm==1.0.15
tinycss2==1.4.0
tokenizers==0.21.0
torch==2.5.1
torchaudio==2.5.1
torchmetrics==1.6.2
torchvision==0.20.1
tornado==6.4.2
tqdm==4.67.1
traitlets==5.14.3
transformers==4.49.0
triton==3.1.0
types-python-dateutil==2.9.0.20241206
typing_extensions @ file:///croot/typing_extensions_1734714854207/work
tzdata==2025.2
uri-template==1.3.0
urllib3 @ file:///croot/urllib3_1737133630106/work
wandb==0.19.8
wcwidth==0.2.13
webcolors==24.11.1
webencodings==0.5.1
websocket-client==1.8.0
Werkzeug==3.1.3
widgetsnbextension==4.0.13

@isaacrob-roboflow
Copy link
Collaborator

interesting, no obvious issues. would you be comfortable sharing your checkpoint? or a minimal reproduction checkpoint that shows the issue without violating your model / data privacy

@PranavDV-VCTI
Copy link
Author

PranavDV-VCTI commented Apr 9, 2025

I was able to successfully convert my checkpoint to an ONNX model using Google Colab, but I'm still encountering issues when attempting the same conversion on my local machine (Tried it on multiple machines).
Regarding the checkpoint, I’m unable to export even the base RFDETR model to ONNX format, so the issue doesn’t seem to be related to my checkpoint.

@WuMaoKai817
Copy link

interesting, no obvious issues. would you be comfortable sharing your checkpoint? or a minimal reproduction checkpoint that shows the issue without violating your model / data privacy很有趣,没有明显的问题。你愿意分享你的检查站吗?或者一个最小的再现检查点,在不违反模型/数据隐私的情况下显示问题

我也遇到了相同的问题,转换一直持续,没有报错

@SkalskiP
Copy link
Collaborator

SkalskiP commented Apr 9, 2025

@PranavDV-VCTI have you tried any non-Windows machine?

@isaacrob-roboflow
Copy link
Collaborator

@SkalskiP it worked in colab which is non windows. @PranavDV-VCTI are all the machines on which it has failed windows?

@SkalskiP
Copy link
Collaborator

SkalskiP commented Apr 9, 2025

@isaacrob-roboflow I know Colab is non windows...

@PranavDV-VCTI said: "I'm still encountering issues when attempting the same conversion on my local machine (Tried it on multiple machines)".

I'm curious if any of those machines was non-Windows? Mostly because I'm curious if that problem exist only on Windows.

@isaacrob-roboflow
Copy link
Collaborator

Oh apologies! :)

@PranavDV-VCTI
Copy link
Author

@SkalskiP @isaacrob-roboflow
All the machines are running Linux; I haven't tested it on a Windows system yet.

@SkalskiP
Copy link
Collaborator

@PranavDV-VCTI didn't you mention WSL?

@PranavDV-VCTI
Copy link
Author

@SkalskiP Apologies, I mistakenly added WSL2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working exports Model exports (ONNX, TensorRT, TFLite, etc.)
Projects
None yet
Development

No branches or pull requests

4 participants