-
Notifications
You must be signed in to change notification settings - Fork 4
/
embedding.py
33 lines (25 loc) · 934 Bytes
/
embedding.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import numpy as np
from keras.models import load_model
from load_data import load_dataset
def get_embedding(model, face):
#For FaceNet we need to standardize the input
std, mean = face.std(), face.mean()
face = (face - mean) / std
sample = np.expand_dims(face, axis=0)
prediction = model.predict(sample)
return prediction[0]
def get_embedded_data(model, trainX):
newTrainX = list()
for face in trainX:
embedding = get_embedding(model, face)
newTrainX.append(embedding)
newTrainX = np.asarray(newTrainX)
return newTrainX
if __name__=='__main__':
input_dir = 'data'
train_dir = os.path.join(input_dir,'processed_data', 'train')
validation_dir = os.path.join(input_dir,'processed_data', 'validation')
trainX, trainy = load_dataset(train_dir)
testX, testy = load_dataset(validation_dir)
trainX, testX = get_embedded_data(trainX, testX)