def get_embedding(img_path):
img = misc.imread(img_path, mode='RGB')
# judge alignment
aligned = align.align(160, img, [0, 0, img.shape[1], img.shape[0]], landmarkIndices=landmarkIndices)
img = facenet.prewhiten(img)
img = np.expand_dims(img, axis=0)
aligned = facenet.prewhiten(aligned)
aligned = np.expand_dims(aligned, axis=0)
# Run forward pass to calculate embeddings
feed_dict = {images_placeholder: img, phase_train_placeholder: False}
emb = sess.run(embeddings, feed_dict=feed_dict)
# Run forward pass to calculate embeddings
feed_dict_aligned = {images_placeholder: aligned, phase_train_placeholder: False}
emb_aligned = sess.run(embeddings, feed_dict=feed_dict_aligned)
return emb.ravel(), emb_aligned.ravel()
# # for test
# import os
# from time import time
# def main(dir_path):
# img_all = os.listdir(dir_path)
# for f in img_all:
# start = time()
# embedding_result = get_embedding(os.path.join(dir_path, f))
# print time() - start
# print embedding_result
#
# main('./data')
评论列表
文章目录