我的程序面部识别和使用“facenet_keras.h5”文件,我必须通过tensorflow ,但这个错误阻止了我。请帮助,谢谢。
下面是代码:
import os
from os import listdir
from PIL import Image as Img
from numpy import asarray
from numpy import expand_dims
from keras.models import load_model
import numpy as np
import pickle
import cv2
#charger classifier et facenet_keras
HaarCascade = cv2.CascadeClassifier(cv2.samples.findFile(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml'))
MyFaceNet = load_model("facenet_keras.h5")
folder = 'photos/' #chemin dossier photos
database = {}
for filename in listdir(folder):
path = folder + filename
gbr1 = cv2.imread(path)
visage = HaarCascade.detectMultiScale(gbr1, 1.1, 4)
if len(visage) > 0:
x1, y1, width, height = visage[0]
else:
x1, y1, width, height = 1, 1, 10, 10
x1, y1 = abs(x1), abs(y1)
x2, y2 = x1 + width, y1 + height
gbr = cv2.cvtColor(gbr1, cv2.COLOR_BGR2RGB)
gbr = Img.fromarray(gbr) # conversion file OpenCV en PIL
gbr_array = asarray(gbr) #convert en tab
face = gbr_array[y1:y2, x1:x2] #prendre face fotsiny
face = Img.fromarray(face) # retour en img
face = face.resize((160, 160))
face = asarray(face)
#normaliser entree
face = face.astype('float32')
mean, std = face.mean(), face.std() #moyenne et ecart type
face = (face - mean) / std
# envoie des entree a facenet
face = expand_dims(face, axis=0)
signature = MyFaceNet.predict(face)
database[os.path.splitext(filename)[0]] = signature
myfile = open("data.pkl", "wb")
pickle.dump(database, myfile)
myfile.close()
myfile = open("data.pkl", "rb")
database = pickle.load(myfile)
myfile.close()
我编写了面部识别程序,要使用“facenet_keras.h5”文件,我必须通过tensorflow ,但这个错误阻止了我。请帮助,谢谢。我编写了面部识别程序,要使用“facenet_keras.h5”文件,我必须通过tensorflow ,但这个错误阻止了我。请帮助,谢谢。我编写了面部识别程序,要使用“facenet_keras.h5”文件,我必须通过tensorflow ,但这个错误阻止了我。请帮助,谢谢。我编写了面部识别程序,要使用“facenet_keras.h5”文件,我必须通过tensorflow ,但这个错误阻止了我。请帮助,谢谢。我编写了面部识别程序,要使用“facenet_keras.h5”文件,我必须通过tensorflow ,但这个错误阻止了我。请帮助,谢谢。我编写了面部识别程序,要使用“facenet_keras.h5”文件,我必须通过tensorflow ,但这个错误阻止了我。请帮助,谢谢。
这是一个错误:
Using TensorFlow backend.
C:\Users\Zouzou\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:458: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Users\Zouzou\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:459: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\Zouzou\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:460: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\Zouzou\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:461: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\Zouzou\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:462: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\Zouzou\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:465: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
2022-10-12 15:26:25.360069: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
C:\Users\Zouzou\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\models.py:252: UserWarning: No training configuration found in save file: the model was *not* compiled. Compile it manually.
warnings.warn('No training configuration found in save file: '
2条答案
按热度按时间u0njafvf1#
如果你只是想运行模型,你应该添加
compile=False
。看起来这个文件中的模型没有编译(它不包括训练所需的数据)。所以干脆改
至
4si2a6ki2#
我终于解决了这个问题。我已经严重安装了keras.
pip install keras
或重新安装tensorflow。