[英]Theano error deep learning python
這是相當標准的openCV代碼,其中的循環將使用haar級聯分類器檢測面部,然后有一個深度學習模型將檢測面部的情緒。 該模型是從2013 kaggle數據集創建的,如果有人想嘗試代碼,則可以從此github帳戶下載該模型。 fer2013_mini_XCEPTION.119-0.65.hdf5只需將一個models
文件夾放在目錄中,並將其重命名為model.h5
https://github.com/oarriaga/face_classification/tree/master/trained_models
該代碼在Tensorflow上正常工作,但是當我運行程序KERAS_BACKEND=theano python haarMOD.py
我收到一個錯誤,可能是由於BLAS庫未正確鏈接? 有人會如何使theano發揮作用嗎? 最終,我試圖使該代碼具有類似的變體,以便在僅與Theano一起使用的Flask服務器上工作。
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上運行基於Ubuntu 18.3和Anaconda 3.6的Linux Mint,這些步驟從機器學習精通到構建深度學習庫。 我也在使用.AVI文件而不是網絡攝像頭,因為我的PC上沒有網絡攝像頭。 將video = cv2.VideoCapture('MovieSample.m4v')
的video = cv2.VideoCapture('MovieSample.m4v')
更改為video = cv2.VideoCapture(0)
以將openCV默認設置為USB攝像機。
https://machinelearningmastery.com/setup-python-environment-machine-learning-deep-learning-anaconda/
model = load_model(MODELPATH) if on CPU, do you have a BLAS library installed Theano can link against?
彈出的錯誤是第17行model = load_model(MODELPATH) if on CPU, do you have a BLAS library installed Theano can link against?
有人可以提示如何解決那件事嗎?
通過在C驅動器C:\\Users\\user\\.keras
以引用"theano"
而不是"tenserflow"
我使代碼可以在Windows計算機上工作
{
"floatx": "float32",
"epsilon": 1e-07,
"backend": "theano",
"image_data_format": "channels_last"
}
然后將在其他stackoverflow帖子中找到的這部分附加代碼添加到我的原始.py文件中
import theano
theano.config.optimizer="None"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.