深入学习python不会出错

深入学习python不会出错,python,opencv,tensorflow,deep-learning,theano,Python,Opencv,Tensorflow,Deep Learning,Theano,这是相当标准的openCV代码,其中循环将使用haar cascade分类器检测人脸,然后有一个深度学习模型将检测人脸中的情感。该模型是从2013年的kaggle数据集创建的,如果有人想试用该代码,我可以从这个github帐户下载该模型fer2013_mini_exception.119-0.65.hdf5只需在目录中放置一个models文件夹,并将其重命名为model.h5 代码在Tensorflow中运行得很好,但是当我运行程序KERAS_BACKEND=theano python haa

这是相当标准的openCV代码,其中循环将使用haar cascade分类器检测人脸,然后有一个深度学习模型将检测人脸中的情感。该模型是从2013年的kaggle数据集创建的,如果有人想试用该代码,我可以从这个github帐户下载该模型fer2013_mini_exception.119-0.65.hdf5只需在目录中放置一个
models
文件夹,并将其重命名为
model.h5

代码在Tensorflow中运行得很好,但是当我运行程序
KERAS_BACKEND=theano python haarMOD.py
时,我得到一个错误,可能是由于BLAS库没有正确链接造成的??有人对如何让theano正常工作有什么想法吗?最终,我尝试在Flask服务器上使用此代码的类似变体,该服务器仅适用于Theano

import cv2
import sys, os
import pandas as pd
import numpy as np
from keras.models import load_model

#KERAS_BACKEND=theano python haarMOD.py

BASEPATH = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, BASEPATH)
os.chdir(BASEPATH)
MODELPATH = './models/model.h5'


emotion_dict = {0: "Angry", 1: "Disgust", 2: "Fear", 3: "Happy", 4: "Sad", 5: "Surprise", 6: "Neutral"}

model = load_model(MODELPATH)

WHITE = [255, 255, 255]

def draw_box(Image, x, y, w, h):
    cv2.line(Image, (x, y), (x + int(w / 5), y), WHITE, 2)
    cv2.line(Image, (x + int((w / 5) * 4), y), (x + w, y), WHITE, 2)
    cv2.line(Image, (x, y), (x, y + int(h / 5)), WHITE, 2)
    cv2.line(Image, (x + w, y), (x + w, y + int(h / 5)), WHITE, 2)
    cv2.line(Image, (x, (y + int(h / 5 * 4))), (x, y + h), WHITE, 2)
    cv2.line(Image, (x, (y + h)), (x + int(w / 5), y + h), WHITE, 2)
    cv2.line(Image, (x + int((w / 5) * 4), y + h), (x + w, y + h), WHITE, 2)
    cv2.line(Image, (x + w, (y + int(h / 5 * 4))), (x + w, y + h), WHITE, 2)

haar_face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
video = cv2.VideoCapture('MovieSample.m4v')


while True:


    check, frame = video.read()


    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = haar_face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5);
    for (x, y, w, h) in faces:
        gray_face = cv2.resize((gray[y:y + h, x:x + w]), (110, 110))
        draw_box(gray, x, y, w, h)
        roi_gray = gray[y:y + h, x:x + w]
        cropped_img = np.expand_dims(np.expand_dims(cv2.resize(roi_gray, (48, 48)), -1), 0)
        cv2.normalize(cropped_img, cropped_img, alpha=0, beta=1, norm_type=cv2.NORM_L2, dtype=cv2.CV_32F)
        prediction = model.predict(cropped_img)
        cv2.putText(gray, emotion_dict[int(np.argmax(prediction))], (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (WHITE), 1, cv2.LINE_AA)

    cv2.imshow("Face Detector", gray)
    cv2.waitKey(1)

    key = cv2.waitKey(1)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break


video.release()
cv2.destroyAllWindows()
<> P>深度学习lib库18.3,基于AcONDA 3.6,在CPU上运行这些Linux操作系统,通过机器学习掌握这些步骤,构建深度学习库。我还使用了.AVI文件而不是网络摄像头,因为我的电脑上没有网络摄像头。请将openCV的
video=cv2.VideoCapture('MovieSample.m4v')
更改为
video=cv2.VideoCapture(0)
默认为USB摄像头


我弹出的错误是第17行
model=load\u model(MODELPATH),如果在CPU上,你是否安装了一个BLAS库Theano can链接?
有人能告诉我如何解决这个问题吗???

我通过编辑我的C驱动器上的.json文件
C:\Users\user\.keras
来引用
“Theano”
,而不是
“tenserflow”

然后在原始的.py文件中添加我在中找到的这段附加代码

import theano
theano.config.optimizer="None"
如果你有“tenserflow”,那么肯定会有错误;它应该是“tensorflow”
import theano
theano.config.optimizer="None"