Open IltonWhatever opened 1 year ago
"but the kernel restart when compiling..." - what does it mean? Do you mean build failure or run-time network inference issue?
in the execution of the code the kernel restarts
This happens when I use this in code: net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA) net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
Please provide complete code reproducer and the model.
import time import cv2
CONFIDENCE_THRESHHOLD = 0.6 NMS_THRESHOLD = 0.6 COLORS = [(0, 255, 255), (255, 255, 0), (0, 255, 0), (255, 0, 0)] txt = [0,0,0] # Text color
class_name = [] with open('coco.names','r') as f: class_names = [cname.strip() for cname in f.readlines()]
net = cv2.dnn.readNet('yolov4-tiny.weights', 'yolov4-tiny.cfg')
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA) net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
model = cv2.dnn_DetectionModel(net) model.setInputParams(size=(416, 416), scale=1/255)
#Use 0 to use webcam or put the path of a video between its extension''
#Example: cap = cv2.VideoCapture('videoplayback.mp4')
cap = cv2.VideoCapture('videoplayback.mp4')
prev_frame = 0 # Previous frame, used to calculate FPS start = 0 while True:
# Frame capture
_, frame = cap.read()
# Window Size
#frame = cv2.resize(frame, (1080, 780))
# Start of MS count
start = time.time()
# detection
classes, scores, boxes = model.detect(frame, CONFIDENCE_THRESHHOLD, NMS_THRESHOLD)
# End of MS Count
end = time.time()
# Cycle through all detections
for (classid, score, box) in zip(classes, scores, boxes):
# Generating colors for classes
color = COLORS[int(classid) % len(COLORS)]
txt = tuple(txt)
# Getting the class name by ID and its Score
label = f'{class_names[classid]} : {int(score*100)}%'
# Drawing the detection box
cv2.rectangle(frame, box, color, 1)
# Writing the class name on top of the object box
cv2.putText(frame, label, (box[0], box[1] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, txt, 3) # Colored
cv2.putText(frame, label, (box[0], box[1] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 1) # Black part
# Calculating the time it took to make the detection
#FPS
fps_label = 1/(start-prev_frame)
prev_frame = start
fps_label = int(fps_label)
fps_label = str(fps_label)
# Writing the FPS on the Image
cv2.putText(frame, fps_label, (0, 25), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0 , 0), 5)
cv2.putText(frame, fps_label, (0, 25), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255 , 0), 3)
# Creating the window
cv2.imshow('detections', frame)
# Pressing Q on the keyboard at any time to close the program
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release() cv2.destroyAllWindows()
Could you attach the model too or, if it's confidential, attach the same model with random (zero) weights?
Model is "Yolo" Yolo Model.zip
Thanks for the model. The model is loaded by model diagnostic tool without issues. Most probably it's CUDNN/CUDA specific issue.
did the code work using CUDA ?
Hi @WanliZhong, please take a look.
@IltonWhatever Hi, I think you can try to downgrade the VS or CUDA version due to compatibility issues. I get the table below from the link https://quasar.ugent.be/files/doc/cuda-msvc-compatibility.html
@IltonWhateverOi, acho que você pode tentar fazer o downgrade da versão VS ou CUDA devido a problemas de compatibilidade. Eu recebo a tabela abaixo do link https://quasar.ugent.be/files/doc/cuda-msvc-compatibility.html
Ok, I am going to try
OpenCV => 4.6 Operating System / Platform => Windows It was too slow to compute DNN with cpu. So I built and checked all of these cmake options to use the GPU.
In the above command, there is no error with CUDA , but the kernel restart when compiling...