ultralytics / ultralytics

Ultralytics YOLO11 🚀
https://docs.ultralytics.com
GNU Affero General Public License v3.0
31.37k stars 6.03k forks source link

Predicted boxes values are always 0 whereas class scores are correct #7027

Closed kleberbueno closed 10 months ago

kleberbueno commented 10 months ago

Search before asking

Question

I have compiled OPENCV 4.8 with CUDA 11.2 in my virtual env. Then I trained a custom dataset with Yolov8 and convert model to an onnx model.

I got Ultralytics opencv yolov8 example and performed inference. When using OPENCV CPU as backend, everything woks perfectly fine. However, when I set OPENCV backend to CUDA, the predicted boxes are always coming as 0 for x,y,w,h. Although for same prediction class scores are ok.

Did anyone faced an issue like that?

Just to let you know, the same opencv version compiled with CUDA works fine for Yolov4 as well.

Any help is much appreciate.

Thanks Kleber

Additional

No response

github-actions[bot] commented 10 months ago

👋 Hello @kleberbueno, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

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

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

kleberbueno commented 10 months ago

Just an update. I have recompiled opencv with cuda, but now for version 4.7. It worked fine. Probably opencv version 4.8 is still not working with yolov8 and cuda.

However, now CPU backended inference is not working anymore. The outputted array values are NaN for all arrays values.

I mean OPENCV 4.8 works only CPU, OPENCV 4.7 works only GPU.

Does anyone? I really appreciate the help.

Thanks

glenn-jocher commented 10 months ago

@kleberbueno hello Kleber 👋,

It's quite intriguing that OpenCV 4.8 works with CPU but not with CUDA for YOLOv8, while OpenCV 4.7 has the inverse issue. It suggests that compatibility might be affecting the interfacing with YOLOv8's ONNX models. The NaN outputs for CPU inference with OpenCV 4.7 could be due to issues in the OpenCV build or a mismatch between the libraries used for compilation and those used at runtime.

Since YOLOv8 is under continuous development, it's possible that updates and changes to the model architecture might not be fully supported by all versions of OpenCV with CUDA acceleration immediately. When you switch between OpenCV versions, make sure to clean and rebuild your environment to avoid any residual configurations leading to these discrepancies.

I suggest reporting this behavior to the OpenCV team as well, as they might provide more detailed assistance on compatibility issues between YOLOv8 ONNX models and the CUDA backend of recent OpenCV versions.

For more detailed guidance on how to use YOLOv8, check our official documentation at https://docs.ultralytics.com.

Thank you for bringing this to our attention, and the entire community appreciates your perseverance. Keep experimenting, and let's hope for a solution soon! 🛠️

kleberbueno commented 10 months ago

Thanks @glenn-jocher I found opencv threads about it.

glenn-jocher commented 10 months ago

@kleberbueno hello Kleber,

Great to hear you've found related threads in the OpenCV community. Do keep an eye on those for potential solutions or workarounds. Your findings are valuable, and sharing them can help others facing similar issues. Best of luck with your project!

Thank you for using YOLOv8, and we look forward to any more feedback or insights you might provide. 😊👍