text_plain_output_1.png
from PIL import Image

from PIL import Image

from keras.models import load_model

from keras.models import load_model

import numpy as np

import numpy as np # linear algebra

import os

import os

import numpy as np
import pandas as pd
import cv2
from matplotlib import pyplot as plt
from keras.models import load_model
from PIL import Image
from sklearn.model_selection import train_test_split
import os

model = load_model('../input/facenet/keras-facenet/model/facenet_keras.h5')

def extract_face(filename, required_size=(160, 160)):
    image = Image.open(filename)
    image = image.convert('RGB')
    pixels = np.asarray(image)
    image = Image.fromarray(pixels)
    image = image.resize(required_size)
    face_array = np.asarray(image)
    return face_array

def load_face(dir):
    faces = list()
    for filename in os.listdir(dir):
        path = dir + filename
        face = extract_face(path)
        faces.append(face)
    return faces
def load_dataset(dir):
    X, y = (list(), list())
    for subdir in os.listdir(dir):
        path = dir + subdir + '/'
        faces = load_face(path)
        labels = [subdir for i in range(len(faces))]
        X.extend(faces)
        y.extend(labels)
    return (np.asarray(X), np.asarray(y))

def get_embedding(face_pixels):
    face_pixels = face_pixels.astype('float32')
    mean, std = (face_pixels.mean(), face_pixels.std())
    face_pixels = (face_pixels - mean) / std
    samples = np.expand_dims(face_pixels, axis=0)
    yhat = model.predict(samples)
    return yhat[0]

data = np.load('../input/new-masked-face/extracted_masked_unmasked.npz')
trainX, trainy, testX, testy = (data['arr_0'], data['arr_1'], data['arr_2'], data['arr_3'])

print(trainX.shape)