Theano错误深度学习python [英] Theano error deep learning python
问题描述
这是相当标准的openCV代码,其中的循环将使用haar级联分类器检测面部,然后有一个深度学习模型将检测面部情绪.该模型是从2013 kaggle数据集创建的,如果有人想试用代码,则可以从此github帐户下载该模型. fer2013_mini_XCEPTION.119-0.65.hdf5 只需在目录中放置一个models
文件夹并将其重命名为model.h5
This is fairly standard openCV code where a loop will detect faces with haar cascade classifier and then there is a deep learning model that will detect the emotion in the face. The model was created from the 2013 kaggle dataset, and I downloaded this model from this github account if someone wants to try out the code. fer2013_mini_XCEPTION.119-0.65.hdf5 Just place a models
folder in your directory and rename it to model.h5
https://github.com/oarriaga/face_classification/tree/master/trained_models
该代码在Tensorflow上正常工作,但是当我运行程序KERAS_BACKEND=theano python haarMOD.py
时,我得到一个错误,可能是由于BLAS库未正确链接?有人会对如何使theano发挥作用有任何想法吗?最终,我试图使该代码具有类似的变体,以便在仅与Theano一起使用的Flask服务器上工作.
The code works just fine with Tensorflow but when I run the program KERAS_BACKEND=theano python haarMOD.py
I get an error that is maybe due to BLAS library not linking properly?? Would anyone have any ideas on how to get theano functioning? Ultimately I am trying to get a similar variation of this code to work on a Flask server which only works with 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()
任何提示都将不胜感激,我正在基于CPU的Anaconda 3.6上运行基于Ubuntu 18.3的Linux Mint,并从机器学习精通到构建深度学习库,采取了以下步骤.我也在使用.AVI文件而不是网络摄像头,因为我的PC上没有网络摄像头.将video = cv2.VideoCapture('MovieSample.m4v')
更改为video = cv2.VideoCapture(0)
,将openCV默认设置为USB摄像机.
Any tips are greatly appreciated, I am running Linux Mint based on Ubuntu 18.3 with Anaconda 3.6 on CPU with these steps from machine learning mastery to build the deep learning library. I am also using a .AVI file instead of a webcam because I dont have a webcam on my PC. Change the video = cv2.VideoCapture('MovieSample.m4v')
to video = cv2.VideoCapture(0)
for openCV to default to a USB camera.
弹出给我的错误是第17行model = load_model(MODELPATH) if on CPU, do you have a BLAS library installed Theano can link against?
有人可以提示如何解决该问题吗?
The error that pops up for me is line 17 model = load_model(MODELPATH) if on CPU, do you have a BLAS library installed Theano can link against?
Can someone give a tip on how to trouble shoot that??
推荐答案
我通过编辑C驱动器C:\Users\user\.keras
上的.json文件以引用"theano"
而不是"tenserflow"
来使代码在Windows机器上工作.
I got the code to work on a Windows machine by editing the .json file on my C drive C:\Users\user\.keras
to reference "theano"
instead of "tenserflow"
{
"floatx": "float32",
"epsilon": 1e-07,
"backend": "theano",
"image_data_format": "channels_last"
}
然后添加我在
这篇关于Theano错误深度学习python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!