Skip to content
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

Export to ONNX with --dynamic gives RunTimeError #7641

Closed
2 tasks done
dmatos2012 opened this issue Apr 29, 2022 · 4 comments · Fixed by #7669
Closed
2 tasks done

Export to ONNX with --dynamic gives RunTimeError #7641

dmatos2012 opened this issue Apr 29, 2022 · 4 comments · Fixed by #7669
Labels
bug Something isn't working

Comments

@dmatos2012
Copy link
Contributor

Search before asking

  • I have searched the YOLOv5 issues and found no similar bug report.

YOLOv5 Component

Export

Bug

Hello,
I saw issue #7268 which is pretty similar to mine. In the suggestion in that case, it mentions to not use --device but I need to use it to export to FP6 (--half). Thus, my error is

ONNX: export failure: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument index in method wrapper__index_select)

If I dont use --dynamic, then model is exported correctly, so my question is if its possible to get an FP16 model export with dynamic axes?. Thanks

Environment

  • YOLO: YOLOv5 🚀 v6.1-165-g1a3ecb8 torch 1.10.0+cu113 CUDA:0 (NVIDIA GeForce RTX 3060 Laptop GPU, 5938MiB)
  • OS: Ubuntu 20.04
  • Python: 3.8.2

Minimal Reproducible Example

python export.py --weights yolov5s.pt --include onnx --half --device 0 --dynamic    

Additional

I would submit a PR, but I think this is a bit beyond my knowledge :)

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@dmatos2012 dmatos2012 added the bug Something isn't working label Apr 29, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Apr 29, 2022

👋 Hello @dmatos2012, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on macOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

@dmatos2012 not all export arguments are mutually compatible. Export with --half or --dynamic.

@dmatos2012
Copy link
Contributor Author

Ah ok, didnt know they were incompatible. Perhaps this below would help to avoid us thinking its an error, but its mainly an incompatibility as you mention `

if half:
    assert device.type != 'cpu' or coreml or xml, '--half only compatible with GPU export, i.e. use --device 0'
   + assert not dynamic, '--half only compatible with static axes'

Thanks

@glenn-jocher
Copy link
Member

glenn-jocher commented Apr 30, 2022

@dmatos2012 that's a great idea! Can you please submit a PR with these improvements?

Please see our ✅ Contributing Guide to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants