# Opencv + cuda + yolov5-v6.0

**URL:** <https://forum.opencv.org/t/opencv-cuda-yolov5-v6-0/6907>\
**Category:** Uncategorized\
**Tags:** dnn, cuda, yolov5\
**Created:** [December 30, 2021, 6:28am UTC](https://forum.opencv.org/t/opencv-cuda-yolov5-v6-0/6907 "2021-12-30T06:28:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vivie](https://avatars.discourse-cdn.com/v4/letter/v/3ec8ea/32.png) [@vivie](https://forum.opencv.org/u/vivie)\
**Post date:** [December 30, 2021, 6:28am UTC](https://forum.opencv.org/t/opencv-cuda-yolov5-v6-0/6907/1 "2021-12-30T06:28:58Z")

</div>

# System information (version)

- OpenCV =\> : 4.5.1
- cuda =\> : 10.2
- cudnn =\> : 8.2
- Operating System / Platform =\> : Windows 64 Bit
- Compiler =\> : Visual Studio 2019

# Detailed description

I compiled the Debug and Release versions of opencv4.5.1+cuda, and used dnn for detection.

- Debug library: test cuda detection and cpu detection, the results are correct;

- Release library: the result of the cuda detection is correct, the result of the cpu detection is abnormal, and the detection result is basically not obtained.

- I tried vs2017+opencv4.5.1, vs2019+opencv4.5.4, the situation is the same.

what is the reason?

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [December 30, 2021, 11:23am UTC](https://forum.opencv.org/t/opencv-cuda-yolov5-v6-0/6907/2 "2021-12-30T11:23:08Z")

</div>

> [@vivie](#):
>
> the result of the cpu detection is abnormal, and the detection result is basically not obtained.

please explain that a bit more. if you have example data and expected results, please add those to your question

---

<div class="post-metadata">

**Author:** ![vivie](https://avatars.discourse-cdn.com/v4/letter/v/3ec8ea/32.png) [@vivie](https://forum.opencv.org/u/vivie)\
**Post date:** [December 31, 2021, 1:26am UTC](https://forum.opencv.org/t/opencv-cuda-yolov5-v6-0/6907/3 "2021-12-31T01:26:55Z")

</div>

-net.setPreferableBackend(cv::dnn::DNN\_BACKEND\_CUDA);  
-net.setPreferableTarget(cv::dnn::DNN\_TARGET\_CUDA);

 ![无标题1](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/f/faeb7e88dd26a0d6785fe97a0e494d153f7c1a60.jpeg)

---

<div class="post-metadata">

**Author:** ![vivie](https://avatars.discourse-cdn.com/v4/letter/v/3ec8ea/32.png) [@vivie](https://forum.opencv.org/u/vivie)\
**Post date:** [December 31, 2021, 1:27am UTC](https://forum.opencv.org/t/opencv-cuda-yolov5-v6-0/6907/4 "2021-12-31T01:27:30Z")

</div>

-net.setPreferableBackend(cv::dnn::DNN\_BACKEND\_OPENCV);|  
-net.setPreferableTarget(cv::dnn::DNN\_TARGET\_CPU);|

 ![无标题2](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/3/3f16c47678dcdb2556f2716b860868fa75a3ec5f.jpeg)
