Ubuntu16.04下跑facenet

原博客地址:https://blog.csdn.net/rookie_wei/article/details/82078373

本博客参照原博客方法执行后自己总结的比较直观的步骤和其中遇到的一些问题,方便以后的学习!

准备:

先自己在Home新建了一个文件夹yhf,用来存放之后的数据集、代码之类的

1、下载lfw数据集至yhf这个文件夹下,并解压

下载链接:http://vis-www.cs.umass.edu/lfw/lfw.tgz

这个数据集下载下来是180.6M,解压之后里面有5749个子文件夹。

 

2、下载Facenet源码文件至yhf,并解压

下载链接:https://codeload.github.com/davidsandberg/facenet/zip/master

文件夹的名字叫 facenet-master,文件夹里的内容如下截图

 

 

3、下载预先训练的模型

下载链接:https://github.com/davidsandberg/facenet

下载文件名为 20180402-114759的这个并解压,得到的文件夹里有4个文件

 

4、安装依赖

打开 facenet-master 这个文件夹,找到requirements.txt文件并打开,删除第一行 tensorflow==1.7,并在该目录下打开终端执行

sudo pip install -r requirements.txt

出现提示;

You are using pip version 18.1, however version 19.0.3 is available.

You should consider upgrading via the 'pip install --upgrade pip' command.

按照上面的命令执行更新pip即可,再运行sudo pip install -r requirements.txt

 

5、预处理图片:人脸检测和人脸对齐

在facenet-master文件夹里执行

python src/align/align_dataset_mtcnn.py ../lfw ../lfw_align_160 --image_size 160 --margin 32 --random_order

出现错误:

Traceback (most recent call last):

  File "src/align/align_dataset_mtcnn.py", line 34, in <module>

    import facenet

ImportError: No module named 'facenet'
解决办法:将src/文件夹路径添加到PYTHONPATH环境变量下

export PYTHONPATH=$PATH:/home/hanjun/yhf/facenet-master/src

再次执行;

python src/align/align_dataset_mtcnn.py ../lfw ../lfw_align_160 --image_size 160 --margin 32 --random_order

等待执行完毕后可以看到最后两行显示:

Total number of images: 13233
Number of successfully aligned images: 13233
 

6、在LFW数据库中验证预先训练的模型

在facenet-master下执行

python src/validate_on_lfw.py ../lfw_align_160/ ../20180402-114759

执行完毕后发现异常:

2019-03-29 18:43:19.428650: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
Model directory: ../20180402-114759
Metagraph file: model-20180402-114759.meta
Checkpoint file: model-20180402-114759.ckpt-275
Runnning forward pass on LFW images
............
Accuracy: 0.98500+-0.00658
Validation rate: 0.90067+-0.02403 @ FAR=0.00067
Area Under Curve (AUC): 0.998
Equal Error Rate (EER): 0.016
2019-03-29 18:47:58.362991: W tensorflow/core/kernels/queue_base.cc:277] _2_input_producer: Skipping cancelled enqueue attempt with queue not closed
2019-03-29 18:47:58.363458: W tensorflow/core/kernels/queue_base.cc:285] _0_FIFOQueueV2: Skipping cancelled dequeue attempt with queue not closed
2019-03-29 18:47:58.363547: W tensorflow/core/kernels/queue_base.cc:285] _0_FIFOQueueV2: Skipping cancelled dequeue attempt with queue not closed
2019-03-29 18:47:58.363555: W tensorflow/core/kernels/queue_base.cc:285] _0_FIFOQueueV2: Skipping cancelled dequeue attempt with queue not closed
2019-03-29 18:47:58.363561: W tensorflow/core/kernels/queue_base.cc:285] _0_FIFOQueueV2: Skipping cancelled dequeue attempt with queue not closed
2019-03-29 18:47:58.363568: W tensorflow/core/kernels/queue_base.cc:285] _0_FIFOQueueV2: Skipping cancelled dequeue attempt with queue not closed
2019-03-29 18:47:58.363573: W tensorflow/core/kernels/queue_base.cc:285] _0_FIFOQueueV2: Skipping cancelled dequeue attempt with queue not closed
2019-03-29 18:47:58.363576: W tensorflow/core/kernels/queue_base.cc:285] _0_FIFOQueueV2: Skipping cancelled dequeue attempt with queue not closed
2019-03-29 18:47:58.363580: W tensorflow/core/kernels/queue_base.cc:285] _0_FIFOQueueV2: Skipping cancelled dequeue attempt with queue not closed
意思是我的 CPU 支持AVX AVX2 (可以加速CPU计算),但安装的 TensorFlow 版本不支持

时间原因,此问题暂时未解决

7、在自己的数据集上应用

在yhf下新建一个文件夹test_images,里面放三张图片0.JPG、1.JPG、2.JPG,其中0.JPG(赵丽颖)、1.JPG(刘亦菲)、2.JPG(刘亦菲)

在facenet-master下运行:

python src/compare.py ../20180402-114759 ../test_images/0.JPG ../test_images/1.JPG ../test_images/2.JPG

得到结果:

Creating networks and loading parameters
2019-03-30 15:38:26.728806: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
/home/hanjun/anaconda2/lib/python2.7/site-packages/scipy/misc/pilutil.py:480: FutureWarning: Conversion of the second argument of issubdtype from `int` to `np.signedinteger` is deprecated. In future, it will be treated as `np.int64 == np.dtype(int).type`.
  if issubdtype(ts, int):
/home/hanjun/anaconda2/lib/python2.7/site-packages/scipy/misc/pilutil.py:483: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  elif issubdtype(type(size), float):
Model directory: ../20180402-114759
Metagraph file: model-20180402-114759.meta
Checkpoint file: model-20180402-114759.ckpt-275
Images:
0: ../test_images/0.JPG
1: ../test_images/1.JPG
2: ../test_images/2.JPG

Distance matrix
        0         1         2     
0    0.0000    1.1520    1.1038  
1    1.1520    0.0000    0.5020  
2    1.1038    0.5020    0.0000 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值