from bumpy import asarray
from PIL import Image
def extract_face_from_image(image, required_size=(64, 64)):
image = imgs[key]
image = (image * 255).round().astype(np.uint8)
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_images
extracted_faces=[extract_face_from_image(img) for img in x]
print(extracted_faces.shape)
因此,我一直尝试使用(2000,100,100)
对图像阵列应用人脸检测,并且每次运行它时,都会遇到内存不足的错误
我正在使用的系统具有64 GB ram Nvidia tesla K80。我试过的是:
减小图像尺寸,切片5个元素以尝试。