-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
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
Inference in TensorRT fails #6934
Comments
👋 Hello @lodm94, 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 [email protected]. RequirementsPython>=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 EnvironmentsYOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf 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. |
@lodm94 TensorRT export and inference examples are shown in Colab notebook Appendix section: |
Hi @glenn-jocher
What about this? |
Even your example does not work:
As you can see, the model instantiation fails returning a NoneType object. |
@lodm94 your code is out of date, before doing anything I would make sure you are using the latest code. In terms of Colab example, it works correctly. The screenshot I just posted in #6934 (comment) is from a test I ran right then (2 hours ago). |
@lodm94 it's likely your GPU (K80) is simply too old for compatibility with current TensorRT. EDIT: this GPU was launched almost 8 years ago, 2014. |
This is likely to be true
Excuse me but EDIT: the problem was common.py, once i updated it it works fine. I saw last commit was 4 days ago, i think i cloned the repo like 4,5 days ago :-) |
Hi @glenn-jocher thanks for your support, now inference in TRT with I trained my model at I exported two model in TRT with different imgsz: one at (544,960) and the other one at (960,960). If i run What i am trying to underline is that with I hope you understand what i am trying to explain |
@lodm94 I don't understand the problem. My TRT screenshot from above already shows how to export and detect at specific height and widths. |
@glenn-jocher Actually i figured out but i didn't manage to delete the comment that you already replied! |
hello,may be the problem is because common.py set default stride as 64 which mean the imgsz must be the multiple of 64,but you use 32 multiple imgsz 544 . you can try as my pr #7342 |
👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs. Access additional YOLOv5 🚀 resources:
Access additional Ultralytics ⚡ resources:
Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed! Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐! |
For what it's worth, I had a similar this morning. The inference environment naively depended on Forcing |
Thank you all for your valuable points. @AndreiBarsan, to accommodate different size inputs during validation with I appreciate everyone's contribution to this discussion and the collaborative effort to resolve this issue. If you have any further questions or encounter any issues, please feel free to ask. |
Search before asking
YOLOv5 Component
Validation, Detection, Export
Bug
Environment
I am working in a Conda env on Ubuntu 20.04 host
Minimal Reproducible Example
I exported onnx and engine model with
export.py
using the following command:python export.py --weights path-to-pt-weights --imgsz 540 960 --batch-size 1 --device 0 --include engine onnx
Then i tried to do inference with engine file using:
python detect.py --weights path-to-engine-file --source val/images/ --device 0 --imgsz 960
Or i tried to run validation with:
python val.py --weights path-to-engine-file --data path-to-yaml-file --device 0 --imgsz 960 --task val
But in both case it returns the error i mentioned above.
Additional
I have some doubt about image-size declaration while exporting the model.
The model should infer on image with fixed size [540,960] and that is the size i used in
export.py
.But during the inference with
detect.py
or during validation withval.py
i can only declare one size, so i use the biggest, 960.If i try to do inference with onnx model with:
python detect.py --weights pesi_sar/best_model_1502.onnx --source val_new/images/ --device 0 --imgsz 960
It obviously returns:
So i tried to export the model declaring only the biggest size with the following command:
python export.py --weights path-to-pt-weights --imgsz 960 --batch-size 1 --device 0 --include engine onnx
The engine model still doesn't work and throw the error mentioned on top.
The onnx model works but it shows different perfomances respect to pytorch model.
That's probably because with onnx weigths the model infers at 960x960, while with pytorch weigths it infers at 544x960 (and thats what i desire!!).
Can you clarify the best practice to use for exporting the model to onnx or engine?
If it is still not clear, i trained my model at 960 image size, but the images i need to process are 540,960 (a quarter of the FHD format btw). I would like to export the model in TRT and keep the same performances as in PyTorch while of course decreasing the inference time.
Cheers
Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: