由于是第一次做 人脸识别,自己摸索,本来师兄是叫我先看MTCNN,不知道怎么回事蹦到了FaceNet了。不过先拿FaceNet做识别出个baseline吧。
CODE_HOME github
Train a classifier on own images
因为完全不知道怎么开始,所以先按照原本流程走一边。按照LFW的训练步骤:
安装依赖项
In the below description it is assumed thata) Tensorflow has been installed , and
b) the Facenet repo has been cloned, and
c) the required python modules has been installed.
下载LFW数据集
wget http://vis-www.cs.umass.edu/lfw/lfw.tgz
解压到 facenet\data\lfw
处理数据(校准/对齐 将数据修剪到与预训练模型使用的数据集一致大小)
1.配置路径
export PYTHONPATH=/home/hszc/Desktop/ZHIHUICHENGSHI/version1/facenet/src
不配置得话会报错
ImportError: No module named facenet
2.处理数据
cd facenet
python src/align/align_dataset_mtcnn.py data/lfw/ data/lfw_160 --image_size 160 --margin 32 --random_order --gpu_memory_fraction 0.25
注意这里!
data/lfw #输入图像文件夹
data/lfw_160 #输出图像文件夹
--image_size 160 --margin 32 --random_order--gpu_memory_fraction 0.25 #指定裁剪后图像大小(如果不指定,默认的裁剪结果是182*182像素的)
下载预训练模型 (能翻墙就直接点击 后面上传网盘链接)
Download and extract the model and place in your favorite models directory (in this example we use ~/models/facenet/
). After extracting the archive there should be a new folder 20180402-114759
with the contents
20180402-114759.pb
model-20180402-114759.ckpt-275.data-00000-of-00001
model-20180402-114759.ckpt-275.index
model-20180402-114759.meta
运行测试
python src/validate_on_lfw.py data/lfw_160 /home/hszc/Desktop/ZHIHUICHENGSHI/version1/facenet/models/facenet/20180402-114759
模型路径 : 绝对路径!
运行结果:
Rnnning forward pass on LFW images ............ Accuracy: 0.98500+-0.00658 Validation rate: 0.90100+-0.02395 @ FAR=0.00067 Area Under Curve (AUC): 0.998 Equal Error Rate (EER): 0.016 2018-06-17 12:42:08.080002: W t
在输出文件夹中多了两个文件,其中有一个是------- bounding_boxes_47735。
参考:
https://github.com/davidsandberg/facenet/wiki/Validate-on-lfw
https://www.cnblogs.com/dyufei/p/8250484.html