python无法找到已保存的笑脸模型文件

No file or directory found at C:\Users\529\PycharmProjects\demo\Utils\models\cnn_fv.h5

import cv2
from keras.models import load_model
import numpy as np
import dlib
model = load_model('C:\\Users\\529\\PycharmProjects\\demo\\Utils\\models\\cnn_fv.h5')
detector = dlib.get_frontal_face_detector()
video = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_SIMPLEX
def rec(img):
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    dets = detector(gray,1)
    if dets is not None:
        for face in dets:
            left = face.left()
            top = face.top()
            right = face.right()
            bottom = face.bottom()
            #绘制矩形框
            cv2.rectangle(img,(left,top),(right,bottom),(0,255,0),2)
            #cv2.resize将原始图像调整为指定大小  scr:原始图像 dsize:输出图像的尺寸
            img1=cv2.resize(img[top:bottom,left:right],dsize=(224,224))
            #颜色空间转换函数
            img1=cv2.cvtColor(img1,cv2.COLOR_BGR2RGB)
            img1 = np.array(img1)/255.
            img_tensor = img1.reshape(1,224,224,3)
            prediction =model.predict(img_tensor)
            if prediction[0][0]<0.5:
                result='nosmile'
            else:
                result='smile'
            print(result)
            cv2.putText(img, result, (left,top), font, 2, (0, 255, 0), 2, cv2.LINE_AA)
        # 实时展示效果画面
        cv2.imshow('smile detector', img)
while video.isOpened():
    res, img_rd = video.read()
    if not res:
        break
    rec(img_rd)
    # 每5毫秒监听一次键盘动作
    if cv2.waitKey(5) & 0xFF == ord('q'):
        break
# 最后,关闭所有窗口
video.release()
cv2.destroyAllWindows()


找到模型文件,直接把路径粘进代码里,避免手敲
你可以写r'路径',加r表示\不再是转义符

检查了这个路径下C:\Users\529\PycharmProjects\demo\Utils\models\cnn_fv.h5 真的有这个h5文件吗。
如果存在就试下反斜杠 model = load_model('C:/Users/529/PycharmProjects/demo/Utils/models/cnn_fv.h5')
或者试下model = load_model('C:\Users\529\PycharmProjects\demo\Utils\models\cnn_fv.h5')

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^