I am trying to run YOLO v4 on OpenCV 4.6 Python with CUDA on WSL 2 with Ubuntu 20.04 (Focal Fossa):
import cv2 as cv
import time
Conf_threshold = 0.4
NMS_threshold = 0.4
COLORS = [(0, 255, 0), (0, 0, 255), (255, 0, 0),
(255, 255, 0), (255, 0, 255), (0, 255, 255)]
class_name = []
with open('classes.txt', 'r') as f:
class_name = [cname.strip() for cname in f.readlines()]
# print(class_name)
net = cv.dnn.readNet('yolov4-tiny.weights', 'yolov4-tiny.cfg')
net.setPreferableBackend(cv.dnn.DNN_BACKEND_CUDA)
net.setPreferableTarget(cv.dnn.DNN_TARGET_CUDA_FP16)
model = cv.dnn_DetectionModel(net)
model.setInputParams(size=(416, 416), scale=1/255, swapRB=True)
cap = cv.VideoCapture('output.avi')
starting_time = time.time()
frame_counter = 0
while True:
ret, frame = cap.read()
frame_counter += 1
if ret == False:
break
classes, scores, boxes = model.detect(frame, Conf_threshold, NMS_threshold)
...
I got the following error:
Traceback (most recent call last): \
File "yolov4.py", line 28, in classes, scores, boxes = model.detect(frame, Conf_threshold, NMS_threshold)
cv2.error: OpenCV(4.6.0-dev) /home/tong/source/opencv/modules/dnn/src/cuda4dnn/csl/memory.hpp:54: error: (-217:Gpu API call) CUDA driver version is insufficient for CUDA runtime version in function 'ManagedPtr'
I have checked the Nvidia driver by using nvidia-smi.exe:
NVIDIA-SMI 516.59 Driver Version: 516.59 CUDA Version: 11.7 |
|-------------------------------+----------------------+----------------------+
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... WDDM | 00000000:0D:00.0 On | N/A |
| 24% 51C P0 44W / 215W | 2711MiB / 8192MiB | 6% Default |
| | | N/A
As well as the CUDA instance installed by dpkg -l | grep cuda-toolkit:
ii cuda-toolkit-11-6 11.6.2-1 amd64 CUDA Toolkit 11.6 meta-package
ii cuda-toolkit-11-6-config-common 11.6.55-1 all Common config package for CUDA Toolkit 11.6.
ii cuda-toolkit-11-7 11.7.0-1 amd64 CUDA Toolkit 11.7 meta-package
ii cuda-toolkit-11-7-config-common 11.7.60-1 all Common config package for CUDA Toolkit 11.7.
ii cuda-toolkit-11-config-common 11.7.60-1 all Common config package for CUDA Toolkit 11.
ii cuda-toolkit-config-common 11.7.60-1 all Common config package for CUDA Toolkit.
OpenCV should be compiled by CUDA 11.7 according to file CMakeCache.txt:
// Version of CUDA as computed from nvcc.
CUDA_VERSION:STRING=11.7
The nvcc is also pointed to 11.7:
nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Tue_May__3_18:49:52_PDT_2022
Cuda compilation tools, release 11.7, V11.7.64
Build cuda_11.7.r11.7/compiler.31294372_0
How can I fix this problem?