1 训练集提取特征值 把特征值保存于 df_train.csv 中
# -*- coding: utf-8 -*-from os import listdir
from os.path import isfile, join
from scipy import miscimport tensorflow as tf
import numpy as np
import pandas as pdimport facenetimport pickle
from sklearn.svm import SVC
import osfrom sklearn import svmtf.Graph().as_default()
sess = tf.Session()
with sess.as_default():# Load the modelfacenet.load_model('20170512-110547/20170512-110547.pb')
# Get input and output tensors
images_placeholder = tf.get_default_graph().get_tensor_by_name("input:0")
embeddings = tf.get_default_graph().get_tensor_by_name("embeddings:0")
phase_train_placeholder = tf.get_default_graph().get_tensor_by_name("phase_train:0")
print(images_placeholder,'--------------',embeddings,'-------------',phase_train_placeholder)#f1path = 'D:/faceRecognition/real_time_face_recognition/faceimg/zhang/f9.jpg'
#f1img = misc.imread(f1path)
#prewhiten_face = facenet.prewhiten(f1img)
#feed_dict = {images_placeholder: [prewhiten_face], phase_train_placeholder: False}
#f1emb = sess.run(embeddings, feed_dict=feed_dict)[0]
#
#mypath = 'D:/faceRecognition/real_time_face_recognition/faceimg/li'
#
#for f in listdir(mypath):
# fn = join(mypath,f)
# if isfile(fn):
# img = misc.imread(fn)
# prewhiten_face = facenet.prewhiten(img)
# feed_dict = {images_placeholder: [prewhiten_face], phase_train_placeholder: False}
# f2emb = sess.run(embeddings, feed_dict=feed_dict)[0]
# dist = np.sqrt(np.sum(np.square(np.subtract(f1emb, f2emb))))
# print('%s: %f' %(f, dist))faceimgpath = 'faceimg2'
emb_array = []
labels = []
class_names = []
classifier_filename_exp = 'faceimg2/c.pkl'
detecter_filename_exp = 'faceimg2/d.pkl'classimgspath = []
train = []
test =[]train_embs = []
train_labels = []
#test_embs = []
#test_labels = []
test_set = []i = 0
for d in listdir(faceimgpath):dn = join(faceimgpath,d)if os.path.isdir(dn):for f in listdir(dn):fn = join(dn, f)if isfile(fn):
# img = misc.imread(fn)
# prewhiten_face = facenet.prewhiten(img)
#