Мой код не может читать лица на изображениях из папки. Он показывает ошибку значения. Вот мой код:
# Definition for extracting faces:
def extract_faces(filename, required_size=(224, 224)):
pixels = pyplot.imread(filename)
detector = MTCNN()
results = detector.detect_faces(pixels)
x1, y1, width, height = results[0]['box']
x2, y2 = x1 + width, y1 + height
face = pixels[y1:y2, x1:x2]
image = Image.fromarray(face)
image = image.resize(required_size)
face_array = asarray(image)
return face_array
# Definition for the face embedding:
def get_embeddings(filenames):
faces = [extract_faces(f) for f in filenames]
samples = asarray(faces, 'float32')
samples = preprocess_input(samples, version=2)
model = VGGFace(model = 'resnet50', include_top = False, input_shape = (224, 224, 3), pooling = 'avg')
yhat = model.predict(samples)
return yhat
# For getting the face embeddings:
embeddings = get_embeddings(faces)
Ошибка:
File "c:/Users/Adarsh Narayanan/Realtime_FR_With_VGGFace2/retrainfaces.py", line 69, in <module>
embeddings = get_embeddings(faces)
File "c:/Users/Adarsh Narayanan/Realtime_FR_With_VGGFace2/retrainfaces.py", line 29, in get_embeddings
faces = [extract_faces(f) for f in filenames]
File "c:/Users/Adarsh Narayanan/Realtime_FR_With_VGGFace2/retrainfaces.py", line 29, in <listcomp>
faces = [extract_faces(f) for f in filenames]
File "c:/Users/Adarsh Narayanan/Realtime_FR_With_VGGFace2/retrainfaces.py", line 22, in extract_faces
image = Image.fromarray(face)
File "C:\Users\Adarsh Narayanan\Anaconda3\lib\site-packages\PIL\Image.py", line 2666, in fromarray
return frombuffer(mode, size, obj, "raw", rawmode, 0, 1)
File "C:\Users\Adarsh Narayanan\Anaconda3\lib\site-packages\PIL\Image.py", line 2609, in frombuffer
return frombytes(mode, size, data, decoder_name, args)
File "C:\Users\Adarsh Narayanan\Anaconda3\lib\site-packages\PIL\Image.py", line 2542, in frombytes
im.frombytes(data, decoder_name, args)
File "C:\Users\Adarsh Narayanan\Anaconda3\lib\site-packages\PIL\Image.py", line 825, in frombytes
d.setimage(self.im)
ValueError: tile cannot extend outside image
Кто-нибудь знает, что мне делать?