Skip to content

The opencv dnn module with cuda can't work correctly #24175

@cos888888

Description

@cos888888

System Information

OpenCV python version: 4.8.0.74
Operating System / Platform: windows 10 LTSC 21H2
Python version: 3.9.13
Cuda version: 11.7
Cudnn version: 8.4.1.50

Detailed description

I use cv2.dnn.readNetFromONNX() to load onnx file which is exported from yolov8. then set net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
I do net.forward() and the result is [ [0,0,0,0, confidence1]
[0,0,0,0, confidence2]
[0,0,0,0, confidence3] ]
that means every bounding box's prediction is all 0 but the prediction of confidence is right. I test the python and c++ way under cuda, the problem is the same. I want the problem can be solve as soon as possible
微信图片_20230818103722

Steps to reproduce

    original_image = batch_img[i]    #original_image is a element which is load from cv2.imread
    [height, width, _] = original_image.shape
    length = max((height, width))
    image = np.zeros((length, length, 3), np.uint8)
    image[0:height, 0:width] = original_image
    scale = length / 640
    
    blob = cv2.dnn.blobFromImage(image, scalefactor=1 / 255, size=(640, 640), swapRB=True)
    
    #cv2.cuda.setDevice(0)
    net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
    net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
    
    net.setInput(blob)
    outputs = net.forward()

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions