「人脸识别」学习FaceNet(4)

使用 calssifier.py

发现一个不错的blog~  很全面,我就不详细写了。

史上最全面的FaceNet使用


# @ 训练模型记住人脸(不是训练网络,网络在这之前已经先训练好了)。
# @ ../lfw/ 是lfw数据集经过 mtcnn 截取以后的结果。否则会影响效果(去除数据集中的人脸外部干扰)
# @     python classifier.py TRAIN ../lfw/ 20170511-185253/ train_20180419_2048.pkl
# @
# @ 测试模型记住人脸的结果。(../data 是测试用的图的路径。)

# @     python classifier.py CLASSIFY ../data/ 20170511-185253/ train_20180419_2048.pkl


通过用图像算出来的向量数据来训练一个SVM分类器,从而对人的身份进行一个判断,同时在.pkl格式的文件中存储每一个分类。这也是作者对于FaceNet程序应用的一个探索。 
这个函数有两个模式,一个模式用来训练,另一个模式用来测试。具体功能如下:

  • 模式= TRAIN:

    • 使用来自数据集的计算出来的向量来训练分类器 
      • 将训练好的分类模型保存为python pickle文件
  • 模式= CLASSIFY:

    • 加载分类模型
    • 使用来自数据集测试部分的嵌入来测试分类器

执行本代码需要添加的参数以及各参数的含义:

  • mode: 设定“TRAIN”和“CLASSIFY”两种模式。
  • data_dir: 图片数据所在文件夹
  • model: 训练好的模型
  • classifier_filename:类似于标签,如果mode参数是TRAIN,那么需要指定一个输出的文件位置(以.pkl结尾,例如/.pkl),如果mode参数是CLASSIFY,那么就需要指定参数的路径(.pkl文件)。

TRAIN:

 
hszc@hszc-System-Product-Name ~/Desktop/ZHIHUICHENGSHI/version1/facenet/src $ python classifier.py TRAIN /home/hszc/Desktop/ZHIHUICHENGSHI/version1/facenet/data/lfw_160 /home/hszc/Desktop/ZHIHUICHENGSHI/version1/facenet/models/facenet/20180402-114759 /home/hszc/Desktop/ZHIHUICHENGSHI/version1/facenet/data/output/out.pkl
classifier.py:61: SyntaxWarning: assertion is always true, perhaps remove parentheses?
  assert(len(cls.image_paths)>0, 'There must be at least one image for each class in the dataset')
/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: 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`.
  from ._conv import register_converters as _register_converters
2018-06-18 21:39:32.589387: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2018-06-18 21:39:32.868219: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-06-18 21:39:32.869040: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 0 with properties: 
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.683
pciBusID: 0000:02:00.0
totalMemory: 10.91GiB freeMemory: 10.75GiB
2018-06-18 21:39:32.869058: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0
2018-06-18 21:39:33.025932: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-06-18 21:39:33.025957: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929]      0 
2018-06-18 21:39:33.025962: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0:   N 
2018-06-18 21:39:33.026156: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10405 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0, compute capability: 6.1)
Number of classes: 5749
Number of images: 13233
Loading feature extraction model
Model directory: /home/hszc/Desktop/ZHIHUICHENGSHI/version1/facenet/models/facenet/20180402-114759
Metagraph file: model-20180402-114759.meta
Checkpoint file: model-20180402-114759.ckpt-275
Calculating features for images
Training classifier
Saved classifier model to file "/home/hszc/Desktop/ZHIHUICHENGSHI/version1/facenet/data/output/out.pkl"

CLASSIFY:

hszc@hszc-System-Product-Name ~/Desktop/ZHIHUICHENGSHI/version1/facenet/src $ python classifier.py CLASSIFY /home/hszc/Desktop/ZHIHUICHENGSHI/version1/facenet/data/test2 /home/hszc/Desktop/ZHIHUICHENGSHI/version1/facenet/models/facenet/20180402-114759 /home/hszc/Desktop/ZHIHUICHENGSHI/version1/facenet/data/output/out.pkl
classifier.py:61: SyntaxWarning: assertion is always true, perhaps remove parentheses?
  assert(len(cls.image_paths)>0, 'There must be at least one image for each class in the dataset')
/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: 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`.
  from ._conv import register_converters as _register_converters
2018-06-18 22:58:29.910830: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2018-06-18 22:58:30.027631: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-06-18 22:58:30.028067: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 0 with properties: 
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.683
pciBusID: 0000:02:00.0
totalMemory: 10.91GiB freeMemory: 10.75GiB
2018-06-18 22:58:30.028078: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0
2018-06-18 22:58:30.170917: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-06-18 22:58:30.170942: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929]      0 
2018-06-18 22:58:30.170946: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0:   N 
2018-06-18 22:58:30.171124: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10405 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0, compute capability: 6.1)
Number of classes: 2
Number of images: 3
Loading feature extraction model
Model directory: /home/hszc/Desktop/ZHIHUICHENGSHI/version1/facenet/models/facenet/20180402-114759
Metagraph file: model-20180402-114759.meta
Checkpoint file: model-20180402-114759.ckpt-275
Calculating features for images
Testing classifier
Loaded classifier model from file "/home/hszc/Desktop/ZHIHUICHENGSHI/version1/facenet/data/output/out.pkl"
   0  Mahmoud Abbas: 0.001
   1  Mahmoud Abbas: 0.002
   2  Michael Schumacher: 0.002
Accuracy: 0.000


参考:

[1]史上最全的FaceNet源码使用方法和讲解(二)

https://blog.csdn.net/u013044310/article/details/80481642

[2]人脸识别-FaceNet-classify.py代码阅读

https://www.cnblogs.com/alexYuin/p/8886727.html


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值