from numpy import asarray
from PIL import Image
import pathlib
def extract_face_from_image(image, required_size=(224, 224)):
detector = MTCNN()
faces = detector.detect_faces(image)
face_images = []
for face in faces:
# extract the bounding box from the requested face
x1, y1, width, height = face['box']
x2, y2 = x1 + width, y1 + height
# extract the face
face_boundary = image[y1:y2, x1:x2]
# resize pixels to the model size
face_image = Image.fromarray(face_boundary)
face_image = face_image.resize(required_size)
face_array = asarray(face_image)
face_images.append(face_array)
return face_image
#detections=extract_face_from_image(y[0])
#trying to loop through the numpy array
detections = [ extract_face_from_image(img) for img in y ]
#print(np.stack(y))
print(np.shape(y[0]))
#plt.imshow(detections[0])
#plt.show()
#Display the first face from the extracted faces
#plt.imshow(extracted_faces[0])
#plt.show() `
хорошо, так что я планировал провести l oop через массив и определить лицо и назначить его обнаружению после того, как столкнулся с ошибкой неправильной формы. Я пошел и проверил, находятся ли изображения в (высота, ширина, размер) формат (для примера, который он распечатал (200,200,3), и который был проверен очень хорошо, но я все еще не уверен, что является причиной этой проблемы, любой совет будет высоко ценится `