tensorflow+XGBoost 人脸识别

该博客介绍了如何结合Tensorflow与XGBoost进行人脸识别。首先从训练集和测试集中提取特征值并保存,然后利用XGBoost训练模型并保存为xgb.model。最后在main.py中加载模型进行预测。
摘要由CSDN通过智能技术生成

1 训练集提取特征值 把特征值保存于 df_train.csv 中

# -*- coding: utf-8 -*-

from os import listdir
from os.path import isfile, join
from scipy import misc

import tensorflow as tf
import numpy as np
import pandas as pd

import facenet

import pickle
from sklearn.svm import SVC
import os

from sklearn import svm





tf.Graph().as_default()
sess = tf.Session()
with sess.as_default():
    # Load the model
    facenet.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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值