我正在尝试使用 YoloV4 和 opencv cuda 构建来检测人是否戴口罩,并使用 deepface 来识别没有戴口罩的人,但我的 VRAM 用完了。有什么解决方法吗?
import cv2
from deepface import DeepFace
CONFIDENCE_THRESHOLD = 0.5
NMS_THRESHOLD = 0.4
COLORS = [(0, 255, 255), (255, 255, 0), (0, 255, 0), (255, 0, 0)]
class_names = []
with open("C:/Users/yashg/Desktop/Yolo/classes.txt", "r") as f:
class_names = [cname.strip() for cname in f.readlines()]
vc = cv2.VideoCapture("C:/Users/yashg/Downloads/tester.mp4")
net = cv2.dnn.readNet("C:/Users/yashg/Desktop/Yolo/darknet-master/cfg/yolov4-custom.cfg", "C:/Users/yashg/Desktop/Yolo/training/yolov4-custom_best.weights")
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, swapRB=True)
while cv2.waitKey(1) < 1:
(grabbed, frame) = vc.read()
if not grabbed:
exit()
classes, scores, boxes = model.detect(frame, CONFIDENCE_THRESHOLD, NMS_THRESHOLD)
for (classid, score, box) in zip(classes, scores, boxes):
color = COLORS[int(classid) % len(COLORS)]
label = "%s : %f" % (class_names[classid], score)
cv2.rectangle(frame, box, color, 2)
cv2.putText(frame, label, (box[0], box[1] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
left, top, width, height = box
cropped_image = frame[top:top+width+20, left:left+width]
if class_names[classid] == "without_mask":
cv2.imwrite("Cropped Image.jpg", cropped_image)
df = DeepFace.find(img_path="Cropped Image.jpg", db_path="C:/Users/yashg/Desktop/dataset",
enforce_detection=False, distance_metric="euclidean_l2")
cv2.imshow("detections", frame)
我遇到了这个错误,并且 yolov4 和 deepface 都可以分别正常工作。