转载自:
【Caffe实践】基于Caffe的人脸识别实现 - 1983的专栏 - 博客频道 - CSDN.NET
http://blog.csdn.net/chenriwei2/article/details/49500687
导言
深度学习深似海、尤其是在图像人脸识别领域,最近几年的顶会和顶刊常常会出现没有太多的理论创新的文章,但是效果摆在那边。
DeepID是深度学习方法进行人脸识别中的一个简单,却高效的一个网络模型,其结构的特点可以概括为两句话:1、训练一个多个人脸的分类器,当训练好之后,就可以把待测试图像放入网络中进行提取特征,2对于提取到的特征,然后就是利用其它的比较方法进行度量。具体的论文可以参照我的一篇论文笔记:【深度学习论文笔记】Deep Learning Face Representation from Predicting 10,000 Classes
首先我们完全参考论文的方法用Caffe设计一个网络结构:
其拓扑图如图1所示:
图1:DeepID的网络结构,图像比较大,需要放大才能看的清楚
网络定义文件:
<code class="hljs css has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">############################# <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">DATA</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">Layer</span> ############################# <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">name</span>: "<span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">face_train_val</span>" <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">top</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"data_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"label_1"</span> name: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"data_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Data"</span> data_param { source: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/media/crw/MyBook/TrainData/LMDB/CASIA-WebFace/10575_64X64/train"</span> backend:LMDB batch_size: <span class="hljs-number" style="box-sizing: border-box;">128</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">transform_param</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">mean_file</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/media/crw/MyBook/TrainData/LMDB/CASIA-WebFace/10575_64X64/mean.binaryproto"</span> mirror: true </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">include</span>: <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">phase</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> TRAIN </span></span></span>} } <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">top</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"data_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"label_1"</span> name: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"data_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Data"</span> data_param { source: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/media/crw/MyBook/TrainData/LMDB/CASIA-WebFace/10575_64X64/val"</span> backend:LMDB batch_size: <span class="hljs-number" style="box-sizing: border-box;">128</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">transform_param</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">mean_file</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/media/crw/MyBook/TrainData/LMDB/CASIA-WebFace/10575_64X64/mean.binaryproto"</span> mirror: true </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">include</span>: <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">phase</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> TEST </span></span></span>} } ############################# <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">CONV</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">NET</span> 1 ############################# <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv1_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Convolution"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"data_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv1_1"</span> param { name: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv1_w"</span> lr_mult: <span class="hljs-number" style="box-sizing: border-box;">1</span> decay_mult: <span class="hljs-number" style="box-sizing: border-box;">1</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">param</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv1_b"</span> lr_mult: <span class="hljs-number" style="box-sizing: border-box;">2</span> decay_mult: <span class="hljs-number" style="box-sizing: border-box;">0</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">convolution_param</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">num_output</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-number" style="box-sizing: border-box;">20</span> kernel_size: <span class="hljs-number" style="box-sizing: border-box;">4</span> stride: <span class="hljs-number" style="box-sizing: border-box;">1</span> weight_filler { type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"gaussian"</span> std: <span class="hljs-number" style="box-sizing: border-box;">0.01</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">bias_filler</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">type</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"constant"</span> value: <span class="hljs-number" style="box-sizing: border-box;">0</span> </span></span></span>} } } <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"relu1_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ReLU"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv1_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv1_1"</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"norm1_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"LRN"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv1_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"norm1_1"</span> lrn_param { local_size: <span class="hljs-number" style="box-sizing: border-box;">5</span> alpha: <span class="hljs-number" style="box-sizing: border-box;">0.0001</span> beta: <span class="hljs-number" style="box-sizing: border-box;">0.75</span> </span></span></span>} } <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"pool1_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Pooling"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"norm1_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"pool1_1"</span> pooling_param { pool: MAX kernel_size: <span class="hljs-number" style="box-sizing: border-box;">2</span> stride: <span class="hljs-number" style="box-sizing: border-box;">2</span> </span></span></span>} } <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv2_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Convolution"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"pool1_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv2_1"</span> param { name: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv2_w"</span> lr_mult: <span class="hljs-number" style="box-sizing: border-box;">1</span> decay_mult: <span class="hljs-number" style="box-sizing: border-box;">1</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">param</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv2_b"</span> lr_mult: <span class="hljs-number" style="box-sizing: border-box;">2</span> decay_mult: <span class="hljs-number" style="box-sizing: border-box;">0</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">convolution_param</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">num_output</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-number" style="box-sizing: border-box;">40</span> kernel_size: <span class="hljs-number" style="box-sizing: border-box;">3</span> group: <span class="hljs-number" style="box-sizing: border-box;">2</span> weight_filler { type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"gaussian"</span> std: <span class="hljs-number" style="box-sizing: border-box;">0.01</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">bias_filler</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">type</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"constant"</span> value: <span class="hljs-number" style="box-sizing: border-box;">0.1</span> </span></span></span>} } } <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"relu2_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ReLU"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv2_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv2_1"</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"norm2_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"LRN"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv2_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"norm2_1"</span> lrn_param { local_size: <span class="hljs-number" style="box-sizing: border-box;">5</span> alpha: <span class="hljs-number" style="box-sizing: border-box;">0.0001</span> beta: <span class="hljs-number" style="box-sizing: border-box;">0.75</span> </span></span></span>} } <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"pool2_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Pooling"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"norm2_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"pool2_1"</span> pooling_param { pool: MAX kernel_size: <span class="hljs-number" style="box-sizing: border-box;">2</span> stride: <span class="hljs-number" style="box-sizing: border-box;">2</span> </span></span></span>} } <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv3_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Convolution"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"pool2_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv3_1"</span> param { name: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv3_w"</span> lr_mult: <span class="hljs-number" style="box-sizing: border-box;">1</span> decay_mult: <span class="hljs-number" style="box-sizing: border-box;">1</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">param</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv3_b"</span> lr_mult: <span class="hljs-number" style="box-sizing: border-box;">2</span> decay_mult: <span class="hljs-number" style="box-sizing: border-box;">0</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">convolution_param</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">num_output</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-number" style="box-sizing: border-box;">60</span> kernel_size: <span class="hljs-number" style="box-sizing: border-box;">3</span> weight_filler { type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"gaussian"</span> std: <span class="hljs-number" style="box-sizing: border-box;">0.01</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">bias_filler</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">type</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"constant"</span> value: <span class="hljs-number" style="box-sizing: border-box;">0</span> </span></span></span>} } } <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"pool3_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Pooling"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv3_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"pool3_1"</span> pooling_param { pool: MAX kernel_size: <span class="hljs-number" style="box-sizing: border-box;">2</span> stride: <span class="hljs-number" style="box-sizing: border-box;">2</span> </span></span></span>} } <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv4_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Convolution"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"pool3_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv4_1"</span> param { name: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv4_w"</span> lr_mult: <span class="hljs-number" style="box-sizing: border-box;">1</span> decay_mult: <span class="hljs-number" style="box-sizing: border-box;">1</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">param</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv4_b"</span> lr_mult: <span class="hljs-number" style="box-sizing: border-box;">2</span> decay_mult: <span class="hljs-number" style="box-sizing: border-box;">0</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">convolution_param</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">num_output</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-number" style="box-sizing: border-box;">80</span> kernel_size: <span class="hljs-number" style="box-sizing: border-box;">2</span> stride: <span class="hljs-number" style="box-sizing: border-box;">2</span> weight_filler { type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"gaussian"</span> std: <span class="hljs-number" style="box-sizing: border-box;">0.01</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">bias_filler</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">type</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"constant"</span> value: <span class="hljs-number" style="box-sizing: border-box;">0.1</span> </span></span></span>} } } <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span><span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"flatten_pool3_1"</span> type:<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Flatten"</span> bottom:<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"pool3_1"</span> top:<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"flatten_pool3_1"</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span><span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"flatten_conv4_1"</span> type:<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Flatten"</span> bottom:<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"conv4_1"</span> top:<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"flatten_conv4_1"</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span><span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"contact_conv"</span> type:<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Concat"</span> bottom:<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"flatten_conv4_1"</span> bottom:<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"flatten_pool3_1"</span> top:<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"contact_conv"</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"deepid_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"InnerProduct"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"contact_conv"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"deepid_1"</span> param { name: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"fc6_w"</span> lr_mult: <span class="hljs-number" style="box-sizing: border-box;">1</span> decay_mult: <span class="hljs-number" style="box-sizing: border-box;">1</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">param</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"fc6_b"</span> lr_mult: <span class="hljs-number" style="box-sizing: border-box;">2</span> decay_mult: <span class="hljs-number" style="box-sizing: border-box;">0</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">inner_product_param</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">num_output</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-number" style="box-sizing: border-box;">160</span> weight_filler { type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"gaussian"</span> std: <span class="hljs-number" style="box-sizing: border-box;">0.005</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">bias_filler</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">type</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"constant"</span> value: <span class="hljs-number" style="box-sizing: border-box;">0.1</span> </span></span></span>} } } <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"relu6_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ReLU"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"deepid_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"deepid_1"</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"drop6_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Dropout"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"deepid_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"deepid_1"</span> dropout_param { dropout_ratio: <span class="hljs-number" style="box-sizing: border-box;">0.5</span> </span></span></span>} } <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"fc8_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"InnerProduct"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"deepid_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"fc8_1"</span> param { name: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"fc8_w"</span> lr_mult: <span class="hljs-number" style="box-sizing: border-box;">1</span> decay_mult: <span class="hljs-number" style="box-sizing: border-box;">1</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">param</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"fc8_b"</span> lr_mult: <span class="hljs-number" style="box-sizing: border-box;">2</span> decay_mult: <span class="hljs-number" style="box-sizing: border-box;">0</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">inner_product_param</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">num_output</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-number" style="box-sizing: border-box;">10575</span> weight_filler { type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"gaussian"</span> std: <span class="hljs-number" style="box-sizing: border-box;">0.01</span> </span></span></span>} <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">bias_filler</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">type</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"constant"</span> value: <span class="hljs-number" style="box-sizing: border-box;">0</span> </span></span></span>} } } <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"accuracy_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Accuracy"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"fc8_1"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"label_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"accuracy_1"</span> include: { phase: TEST </span></span></span>} } <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">layer</span> <span class="hljs-rules" style="box-sizing: border-box;">{ <span class="hljs-rule" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">name</span>:<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 102, 102);"> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"loss_1"</span> type: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"SoftmaxWithLoss"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"fc8_1"</span> bottom: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"label_1"</span> top: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"loss_1"</span> #loss_weight: <span class="hljs-number" style="box-sizing: border-box;">0.5</span> </span></span></span>} </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li><li style="box-sizing: border-box; padding: 0px 5px;">54</li><li style="box-sizing: border-box; padding: 0px 5px;">55</li><li style="box-sizing: border-box; padding: 0px 5px;">56</li><li style="box-sizing: border-box; padding: 0px 5px;">57</li><li style="box-sizing: border-box; padding: 0px 5px;">58</li><li style="box-sizing: border-box; padding: 0px 5px;">59</li><li style="box-sizing: border-box; padding: 0px 5px;">60</li><li style="box-sizing: border-box; padding: 0px 5px;">61</li><li style="box-sizing: border-box; padding: 0px 5px;">62</li><li style="box-sizing: border-box; padding: 0px 5px;">63</li><li style="box-sizing: border-box; padding: 0px 5px;">64</li><li style="box-sizing: border-box; padding: 0px 5px;">65</li><li style="box-sizing: border-box; padding: 0px 5px;">66</li><li style="box-sizing: border-box; padding: 0px 5px;">67</li><li style="box-sizing: border-box; padding: 0px 5px;">68</li><li style="box-sizing: border-box; padding: 0px 5px;">69</li><li style="box-sizing: border-box; padding: 0px 5px;">70</li><li style="box-sizing: border-box; padding: 0px 5px;">71</li><li style="box-sizing: border-box; padding: 0px 5px;">72</li><li style="box-sizing: border-box; padding: 0px 5px;">73</li><li style="box-sizing: border-box; padding: 0px 5px;">74</li><li style="box-sizing: border-box; padding: 0px 5px;">75</li><li style="box-sizing: border-box; padding: 0px 5px;">76</li><li style="box-sizing: border-box; padding: 0px 5px;">77</li><li style="box-sizing: border-box; padding: 0px 5px;">78</li><li style="box-sizing: border-box; padding: 0px 5px;">79</li><li style="box-sizing: border-box; padding: 0px 5px;">80</li><li style="box-sizing: border-box; padding: 0px 5px;">81</li><li style="box-sizing: border-box; padding: 0px 5px;">82</li><li style="box-sizing: border-box; padding: 0px 5px;">83</li><li style="box-sizing: border-box; padding: 0px 5px;">84</li><li style="box-sizing: border-box; padding: 0px 5px;">85</li><li style="box-sizing: border-box; padding: 0px 5px;">86</li><li style="box-sizing: border-box; padding: 0px 5px;">87</li><li style="box-sizing: border-box; padding: 0px 5px;">88</li><li style="box-sizing: border-box; padding: 0px 5px;">89</li><li style="box-sizing: border-box; padding: 0px 5px;">90</li><li style="box-sizing: border-box; padding: 0px 5px;">91</li><li style="box-sizing: border-box; padding: 0px 5px;">92</li><li style="box-sizing: border-box; padding: 0px 5px;">93</li><li style="box-sizing: border-box; padding: 0px 5px;">94</li><li style="box-sizing: border-box; padding: 0px 5px;">95</li><li style="box-sizing: border-box; padding: 0px 5px;">96</li><li style="box-sizing: border-box; padding: 0px 5px;">97</li><li style="box-sizing: border-box; padding: 0px 5px;">98</li><li style="box-sizing: border-box; padding: 0px 5px;">99</li><li style="box-sizing: border-box; padding: 0px 5px;">100</li><li style="box-sizing: border-box; padding: 0px 5px;">101</li><li style="box-sizing: border-box; padding: 0px 5px;">102</li><li style="box-sizing: border-box; padding: 0px 5px;">103</li><li style="box-sizing: border-box; padding: 0px 5px;">104</li><li style="box-sizing: border-box; padding: 0px 5px;">105</li><li style="box-sizing: border-box; padding: 0px 5px;">106</li><li style="box-sizing: border-box; padding: 0px 5px;">107</li><li style="box-sizing: border-box; padding: 0px 5px;">108</li><li style="box-sizing: border-box; padding: 0px 5px;">109</li><li style="box-sizing: border-box; padding: 0px 5px;">110</li><li style="box-sizing: border-box; padding: 0px 5px;">111</li><li style="box-sizing: border-box; padding: 0px 5px;">112</li><li style="box-sizing: border-box; padding: 0px 5px;">113</li><li style="box-sizing: border-box; padding: 0px 5px;">114</li><li style="box-sizing: border-box; padding: 0px 5px;">115</li><li style="box-sizing: border-box; padding: 0px 5px;">116</li><li style="box-sizing: border-box; padding: 0px 5px;">117</li><li style="box-sizing: border-box; padding: 0px 5px;">118</li><li style="box-sizing: border-box; padding: 0px 5px;">119</li><li style="box-sizing: border-box; padding: 0px 5px;">120</li><li style="box-sizing: border-box; padding: 0px 5px;">121</li><li style="box-sizing: border-box; padding: 0px 5px;">122</li><li style="box-sizing: border-box; padding: 0px 5px;">123</li><li style="box-sizing: border-box; padding: 0px 5px;">124</li><li style="box-sizing: border-box; padding: 0px 5px;">125</li><li style="box-sizing: border-box; padding: 0px 5px;">126</li><li style="box-sizing: border-box; padding: 0px 5px;">127</li><li style="box-sizing: border-box; padding: 0px 5px;">128</li><li style="box-sizing: border-box; padding: 0px 5px;">129</li><li style="box-sizing: border-box; padding: 0px 5px;">130</li><li style="box-sizing: border-box; padding: 0px 5px;">131</li><li style="box-sizing: border-box; padding: 0px 5px;">132</li><li style="box-sizing: border-box; padding: 0px 5px;">133</li><li style="box-sizing: border-box; padding: 0px 5px;">134</li><li style="box-sizing: border-box; padding: 0px 5px;">135</li><li style="box-sizing: border-box; padding: 0px 5px;">136</li><li style="box-sizing: border-box; padding: 0px 5px;">137</li><li style="box-sizing: border-box; padding: 0px 5px;">138</li><li style="box-sizing: border-box; padding: 0px 5px;">139</li><li style="box-sizing: border-box; padding: 0px 5px;">140</li><li style="box-sizing: border-box; padding: 0px 5px;">141</li><li style="box-sizing: border-box; padding: 0px 5px;">142</li><li style="box-sizing: border-box; padding: 0px 5px;">143</li><li style="box-sizing: border-box; padding: 0px 5px;">144</li><li style="box-sizing: border-box; padding: 0px 5px;">145</li><li style="box-sizing: border-box; padding: 0px 5px;">146</li><li style="box-sizing: border-box; padding: 0px 5px;">147</li><li style="box-sizing: border-box; padding: 0px 5px;">148</li><li style="box-sizing: border-box; padding: 0px 5px;">149</li><li style="box-sizing: border-box; padding: 0px 5px;">150</li><li style="box-sizing: border-box; padding: 0px 5px;">151</li><li style="box-sizing: border-box; padding: 0px 5px;">152</li><li style="box-sizing: border-box; padding: 0px 5px;">153</li><li style="box-sizing: border-box; padding: 0px 5px;">154</li><li style="box-sizing: border-box; padding: 0px 5px;">155</li><li style="box-sizing: border-box; padding: 0px 5px;">156</li><li style="box-sizing: border-box; padding: 0px 5px;">157</li><li style="box-sizing: border-box; padding: 0px 5px;">158</li><li style="box-sizing: border-box; padding: 0px 5px;">159</li><li style="box-sizing: border-box; padding: 0px 5px;">160</li><li style="box-sizing: border-box; padding: 0px 5px;">161</li><li style="box-sizing: border-box; padding: 0px 5px;">162</li><li style="box-sizing: border-box; padding: 0px 5px;">163</li><li style="box-sizing: border-box; padding: 0px 5px;">164</li><li style="box-sizing: border-box; padding: 0px 5px;">165</li><li style="box-sizing: border-box; padding: 0px 5px;">166</li><li style="box-sizing: border-box; padding: 0px 5px;">167</li><li style="box-sizing: border-box; padding: 0px 5px;">168</li><li style="box-sizing: border-box; padding: 0px 5px;">169</li><li style="box-sizing: border-box; padding: 0px 5px;">170</li><li style="box-sizing: border-box; padding: 0px 5px;">171</li><li style="box-sizing: border-box; padding: 0px 5px;">172</li><li style="box-sizing: border-box; padding: 0px 5px;">173</li><li style="box-sizing: border-box; padding: 0px 5px;">174</li><li style="box-sizing: border-box; padding: 0px 5px;">175</li><li style="box-sizing: border-box; padding: 0px 5px;">176</li><li style="box-sizing: border-box; padding: 0px 5px;">177</li><li style="box-sizing: border-box; padding: 0px 5px;">178</li><li style="box-sizing: border-box; padding: 0px 5px;">179</li><li style="box-sizing: border-box; padding: 0px 5px;">180</li><li style="box-sizing: border-box; padding: 0px 5px;">181</li><li style="box-sizing: border-box; padding: 0px 5px;">182</li><li style="box-sizing: border-box; padding: 0px 5px;">183</li><li style="box-sizing: border-box; padding: 0px 5px;">184</li><li style="box-sizing: border-box; padding: 0px 5px;">185</li><li style="box-sizing: border-box; padding: 0px 5px;">186</li><li style="box-sizing: border-box; padding: 0px 5px;">187</li><li style="box-sizing: border-box; padding: 0px 5px;">188</li><li style="box-sizing: border-box; padding: 0px 5px;">189</li><li style="box-sizing: border-box; padding: 0px 5px;">190</li><li style="box-sizing: border-box; padding: 0px 5px;">191</li><li style="box-sizing: border-box; padding: 0px 5px;">192</li><li style="box-sizing: border-box; padding: 0px 5px;">193</li><li style="box-sizing: border-box; padding: 0px 5px;">194</li><li style="box-sizing: border-box; padding: 0px 5px;">195</li><li style="box-sizing: border-box; padding: 0px 5px;">196</li><li style="box-sizing: border-box; padding: 0px 5px;">197</li><li style="box-sizing: border-box; padding: 0px 5px;">198</li><li style="box-sizing: border-box; padding: 0px 5px;">199</li><li style="box-sizing: border-box; padding: 0px 5px;">200</li><li style="box-sizing: border-box; padding: 0px 5px;">201</li><li style="box-sizing: border-box; padding: 0px 5px;">202</li><li style="box-sizing: border-box; padding: 0px 5px;">203</li><li style="box-sizing: border-box; padding: 0px 5px;">204</li><li style="box-sizing: border-box; padding: 0px 5px;">205</li><li style="box-sizing: border-box; padding: 0px 5px;">206</li><li style="box-sizing: border-box; padding: 0px 5px;">207</li><li style="box-sizing: border-box; padding: 0px 5px;">208</li><li style="box-sizing: border-box; padding: 0px 5px;">209</li><li style="box-sizing: border-box; padding: 0px 5px;">210</li><li style="box-sizing: border-box; padding: 0px 5px;">211</li><li style="box-sizing: border-box; padding: 0px 5px;">212</li><li style="box-sizing: border-box; padding: 0px 5px;">213</li><li style="box-sizing: border-box; padding: 0px 5px;">214</li><li style="box-sizing: border-box; padding: 0px 5px;">215</li><li style="box-sizing: border-box; padding: 0px 5px;">216</li><li style="box-sizing: border-box; padding: 0px 5px;">217</li><li style="box-sizing: border-box; padding: 0px 5px;">218</li><li style="box-sizing: border-box; padding: 0px 5px;">219</li><li style="box-sizing: border-box; padding: 0px 5px;">220</li><li style="box-sizing: border-box; padding: 0px 5px;">221</li><li style="box-sizing: border-box; padding: 0px 5px;">222</li><li style="box-sizing: border-box; padding: 0px 5px;">223</li><li style="box-sizing: border-box; padding: 0px 5px;">224</li><li style="box-sizing: border-box; padding: 0px 5px;">225</li><li style="box-sizing: border-box; padding: 0px 5px;">226</li><li style="box-sizing: border-box; padding: 0px 5px;">227</li><li style="box-sizing: border-box; padding: 0px 5px;">228</li><li style="box-sizing: border-box; padding: 0px 5px;">229</li><li style="box-sizing: border-box; padding: 0px 5px;">230</li><li style="box-sizing: border-box; padding: 0px 5px;">231</li><li style="box-sizing: border-box; padding: 0px 5px;">232</li><li style="box-sizing: border-box; padding: 0px 5px;">233</li><li style="box-sizing: border-box; padding: 0px 5px;">234</li><li style="box-sizing: border-box; padding: 0px 5px;">235</li><li style="box-sizing: border-box; padding: 0px 5px;">236</li><li style="box-sizing: border-box; padding: 0px 5px;">237</li><li style="box-sizing: border-box; padding: 0px 5px;">238</li><li style="box-sizing: border-box; padding: 0px 5px;">239</li><li style="box-sizing: border-box; padding: 0px 5px;">240</li><li style="box-sizing: border-box; padding: 0px 5px;">241</li><li style="box-sizing: border-box; padding: 0px 5px;">242</li><li style="box-sizing: border-box; padding: 0px 5px;">243</li><li style="box-sizing: border-box; padding: 0px 5px;">244</li><li style="box-sizing: border-box; padding: 0px 5px;">245</li><li style="box-sizing: border-box; padding: 0px 5px;">246</li><li style="box-sizing: border-box; padding: 0px 5px;">247</li><li style="box-sizing: border-box; padding: 0px 5px;">248</li><li style="box-sizing: border-box; padding: 0px 5px;">249</li><li style="box-sizing: border-box; padding: 0px 5px;">250</li><li style="box-sizing: border-box; padding: 0px 5px;">251</li><li style="box-sizing: border-box; padding: 0px 5px;">252</li><li style="box-sizing: border-box; padding: 0px 5px;">253</li><li style="box-sizing: border-box; padding: 0px 5px;">254</li><li style="box-sizing: border-box; padding: 0px 5px;">255</li><li style="box-sizing: border-box; padding: 0px 5px;">256</li><li style="box-sizing: border-box; padding: 0px 5px;">257</li><li style="box-sizing: border-box; padding: 0px 5px;">258</li><li style="box-sizing: border-box; padding: 0px 5px;">259</li><li style="box-sizing: border-box; padding: 0px 5px;">260</li><li style="box-sizing: border-box; padding: 0px 5px;">261</li><li style="box-sizing: border-box; padding: 0px 5px;">262</li><li style="box-sizing: border-box; padding: 0px 5px;">263</li><li style="box-sizing: border-box; padding: 0px 5px;">264</li><li style="box-sizing: border-box; padding: 0px 5px;">265</li><li style="box-sizing: border-box; padding: 0px 5px;">266</li><li style="box-sizing: border-box; padding: 0px 5px;">267</li><li style="box-sizing: border-box; padding: 0px 5px;">268</li><li style="box-sizing: border-box; padding: 0px 5px;">269</li><li style="box-sizing: border-box; padding: 0px 5px;">270</li><li style="box-sizing: border-box; padding: 0px 5px;">271</li><li style="box-sizing: border-box; padding: 0px 5px;">272</li><li style="box-sizing: border-box; padding: 0px 5px;">273</li><li style="box-sizing: border-box; padding: 0px 5px;">274</li><li style="box-sizing: border-box; padding: 0px 5px;">275</li><li style="box-sizing: border-box; padding: 0px 5px;">276</li><li style="box-sizing: border-box; padding: 0px 5px;">277</li><li style="box-sizing: border-box; padding: 0px 5px;">278</li><li style="box-sizing: border-box; padding: 0px 5px;">279</li><li style="box-sizing: border-box; padding: 0px 5px;">280</li><li style="box-sizing: border-box; padding: 0px 5px;">281</li><li style="box-sizing: border-box; padding: 0px 5px;">282</li><li style="box-sizing: border-box; padding: 0px 5px;">283</li><li style="box-sizing: border-box; padding: 0px 5px;">284</li><li style="box-sizing: border-box; padding: 0px 5px;">285</li><li style="box-sizing: border-box; padding: 0px 5px;">286</li><li style="box-sizing: border-box; padding: 0px 5px;">287</li><li style="box-sizing: border-box; padding: 0px 5px;">288</li><li style="box-sizing: border-box; padding: 0px 5px;">289</li><li style="box-sizing: border-box; padding: 0px 5px;">290</li><li style="box-sizing: border-box; padding: 0px 5px;">291</li><li style="box-sizing: border-box; padding: 0px 5px;">292</li><li style="box-sizing: border-box; padding: 0px 5px;">293</li><li style="box-sizing: border-box; padding: 0px 5px;">294</li><li style="box-sizing: border-box; padding: 0px 5px;">295</li><li style="box-sizing: border-box; padding: 0px 5px;">296</li><li style="box-sizing: border-box; padding: 0px 5px;">297</li><li style="box-sizing: border-box; padding: 0px 5px;">298</li><li style="box-sizing: border-box; padding: 0px 5px;">299</li><li style="box-sizing: border-box; padding: 0px 5px;">300</li><li style="box-sizing: border-box; padding: 0px 5px;">301</li><li style="box-sizing: border-box; padding: 0px 5px;">302</li><li style="box-sizing: border-box; padding: 0px 5px;">303</li><li style="box-sizing: border-box; padding: 0px 5px;">304</li><li style="box-sizing: border-box; padding: 0px 5px;">305</li><li style="box-sizing: border-box; padding: 0px 5px;">306</li><li style="box-sizing: border-box; padding: 0px 5px;">307</li><li style="box-sizing: border-box; padding: 0px 5px;">308</li><li style="box-sizing: border-box; padding: 0px 5px;">309</li><li style="box-sizing: border-box; padding: 0px 5px;">310</li><li style="box-sizing: border-box; padding: 0px 5px;">311</li><li style="box-sizing: border-box; padding: 0px 5px;">312</li><li style="box-sizing: border-box; padding: 0px 5px;">313</li><li style="box-sizing: border-box; padding: 0px 5px;">314</li><li style="box-sizing: border-box; padding: 0px 5px;">315</li><li style="box-sizing: border-box; padding: 0px 5px;">316</li><li style="box-sizing: border-box; padding: 0px 5px;">317</li><li style="box-sizing: border-box; padding: 0px 5px;">318</li><li style="box-sizing: border-box; padding: 0px 5px;">319</li><li style="box-sizing: border-box; padding: 0px 5px;">320</li><li style="box-sizing: border-box; padding: 0px 5px;">321</li><li style="box-sizing: border-box; padding: 0px 5px;">322</li><li style="box-sizing: border-box; padding: 0px 5px;">323</li><li style="box-sizing: border-box; padding: 0px 5px;">324</li><li style="box-sizing: border-box; padding: 0px 5px;">325</li><li style="box-sizing: border-box; padding: 0px 5px;">326</li><li style="box-sizing: border-box; padding: 0px 5px;">327</li><li style="box-sizing: border-box; padding: 0px 5px;">328</li><li style="box-sizing: border-box; padding: 0px 5px;">329</li><li style="box-sizing: border-box; padding: 0px 5px;">330</li><li style="box-sizing: border-box; padding: 0px 5px;">331</li><li style="box-sizing: border-box; padding: 0px 5px;">332</li><li style="box-sizing: border-box; padding: 0px 5px;">333</li></ul>
2. 数据选择
训练一个好的深度模型,一个好的训练数据是必不可少的。针对人脸识别的数据,目前公开的数据也有很多:比如最近的MegaFace、港大的Celbra A、中科研的WebFace 等等。在这里,我选择WebFace人脸数据库作为训练(人脸库不是很干净,噪声较多),图像公共50万张左右,共10575个人,但是数据不平衡。
要评测一个算法的性能,需要找一个公平的比对数据库来评测,在人脸验证中,LFW数据库无疑是最好的选择。在lfw评测中,给出6000千对人脸图像对进行人匹配。
3. 数据处理
训练数据和测试数据都选择好之后,就需要进行数据处理了,为了提供较好的识别准确度,我采用了训练数据和测试数据统一的预处理方法(虽然LFW上有提供已经预处理过的人脸图像,但是预处理的具体参数还是未知的),测试数据和训练数据都采样相同的人脸检测和对齐方法。
主要分为3个步骤:
1,人脸检测
2,人脸特征点检测
3、人脸的对齐
这三个步骤可以用我做的一个小工具:FaceTools 来一键完成。
具体来说,需要选择一个标准的人脸图像作为对齐的基准,我挑选一位帅哥当标准图像:
如图:
训练数据通过对齐后是这样的:
LFW测试数据通过对齐后是这样的:
4.数据转换
图像处理好之后,需要将其转化为Caffe 可以接受的格式。虽然Caffe支持直接读图像文件的格式进行训练,但是这种方式磁盘IO会比较的大,所以我这里不采用图像列表的方式,而是将训练和验证图片都转化为LMDB的格式处理。
4.1 划分训练集验证集
划分训练集和验证集(我采样的是9:1的比例)
脚本如下:
<code class="hljs python has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># -*- coding: utf-8 -*-</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">""" Created on Mon Jun 8 14:15:21 2015 @author: crw """</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">import</span> os <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">def</span> <span class="hljs-title" style="box-sizing: border-box;">div_database</span><span class="hljs-params" style="color: rgb(102, 0, 102); box-sizing: border-box;">(filepath,savepath,top_num=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1000</span>,equal_num=False)</span>:</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">''' @brief: 提取webface人脸数据 @param : filepath 文件路径 @param : top_num=1000,表示提取的类别数目 @param : equal_num 是否强制每个人都相同 '''</span> dirlists=os.listdir(filepath) dict_id_num={} <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> subdir <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> dirlists: dict_id_num[subdir]=len(os.listdir(os.path.join(filepath,subdir))) <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#sorted(dict_id_num.items, key=lambda dict_id_num:dict_id_num[1])</span> sorted_num_id=sorted([(v, k) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> k, v <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> dict_id_num.items()], reverse=<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">True</span>) select_ids=sorted_num_id[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>:top_num] <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> equal_num == <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">True</span>: trainfile=save_path+<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'train_'</span>+str(top_num)+<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'_equal_.list'</span> testfile=save_path+<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'val_'</span>+str(top_num)+<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'_qeual.list'</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span>: trainfile=save_path+<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'train_'</span>+str(top_num)+<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'.list'</span> testfile=save_path+<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'val_'</span>+str(top_num)+<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'.list'</span> fid_train=open(trainfile,<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'w'</span>) fid_test=open(testfile,<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'w'</span>) pid=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> select_id <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> select_ids: subdir=select_id[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>] filenamelist=os.listdir(os.path.join(filepath,subdir)) num=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> filename <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> filenamelist : <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#print select_ids[top_num-1]</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> equal_num==<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">True</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">and</span> num>select_ids[top_num-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>][<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]: <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">break</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> num%<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>!=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>: fid_train.write(os.path.join(subdir,filename)+<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'\t'</span>+str(pid)+<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'\n'</span>) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span>: fid_test.write(os.path.join(subdir,filename)+<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'\t'</span>+str(pid)+<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'\n'</span>) num=num+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> pid=pid+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> fid_train.close() fid_test.close() <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> __name__==<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'__main__'</span>: data_path = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'/media/crw/MyBook/MyDataset/CASIA-WebFace/croped'</span> save_path = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'/media/crw/MyBook/MyDataset/CASIA-WebFace/'</span> div_database(data_path,save_path, top_num=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10575</span>, equal_num=<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">False</span>)</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li></ul>
4.2 数据转换
再调用Caffe 提供的转化函数:
脚本如下:
<code class="hljs bash has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-shebang" style="color: rgb(0, 102, 102); box-sizing: border-box;">#!/usr/bin/env sh</span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># Create the image to lmdb inputs</span> TOOLS=/home/crw/caffe-master/.build_release/tools <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#图像文件的存放位置</span> TRAIN_DATA_ROOT=/media/crw/MyBook/MyDataset/CASIA-WebFace/croped/ VAL_DATA_ROOT=/media/crw/MyBook/MyDataset/CASIA-WebFace/croped/ IMAGE_LIST_ROOT=/media/crw/MyBook/MyDataset/CASIA-WebFace/ <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#LMDB文件的存放位置</span> ROOT_LMDB=/media/crw/MyBook/TrainData/LMDB/CASIA-WebFace/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10575</span>_64X64 <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># Set RESIZE=true to resize the images to 256x256. Leave as false if images have</span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># already been resized using another tool.</span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#是否剪切为相同的大小</span> RESIZE=<span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">true</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$RESIZE</span>; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">then</span> RESIZE_HEIGHT=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64</span> RESIZE_WIDTH=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span> RESIZE_HEIGHT=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> RESIZE_WIDTH=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">fi</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> [ ! <span class="hljs-operator" style="box-sizing: border-box;">-d</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$TRAIN_DATA_ROOT</span>"</span> ]; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">then</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">echo</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Error: TRAIN_DATA_ROOT is not a path to a directory: <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$TRAIN_DATA_ROOT</span>"</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">echo</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Set the TRAIN_DATA_ROOT variable in create_imagenet.sh to the path"</span> \ <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"where the ImageNet training data is stored."</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">exit</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">fi</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> [ ! <span class="hljs-operator" style="box-sizing: border-box;">-d</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$VAL_DATA_ROOT</span>"</span> ]; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">then</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">echo</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Error: VAL_DATA_ROOT is not a path to a directory: <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$VAL_DATA_ROOT</span>"</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">echo</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Set the VAL_DATA_ROOT variable in create_imagenet.sh to the path"</span> \ <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"where the ImageNet validation data is stored."</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">exit</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">fi</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">echo</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Creating train lmdb..."</span> GLOG_logtostderr=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$TOOLS</span>/convert_imageset \ --resize_height=<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$RESIZE_HEIGHT</span> \ --resize_width=<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$RESIZE_WIDTH</span> \ --shuffle \ <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$TRAIN_DATA_ROOT</span> \ <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$IMAGE_LIST_ROOT</span>/train_10575.list \ <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ROOT_LMDB</span>/train <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">echo</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Creating val lmdb..."</span> GLOG_logtostderr=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$TOOLS</span>/convert_imageset \ --resize_height=<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$RESIZE_HEIGHT</span> \ --resize_width=<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$RESIZE_WIDTH</span> \ --shuffle \ <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$VAL_DATA_ROOT</span> \ <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$IMAGE_LIST_ROOT</span>/val_10575.list \ <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ROOT_LMDB</span>/val <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$TOOLS</span>/compute_image_mean <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ROOT_LMDB</span>/train \ <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ROOT_LMDB</span>/mean.binaryproto <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">echo</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Done."</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li><li style="box-sizing: border-box; padding: 0px 5px;">54</li><li style="box-sizing: border-box; padding: 0px 5px;">55</li><li style="box-sizing: border-box; padding: 0px 5px;">56</li><li style="box-sizing: border-box; padding: 0px 5px;">57</li><li style="box-sizing: border-box; padding: 0px 5px;">58</li><li style="box-sizing: border-box; padding: 0px 5px;">59</li><li style="box-sizing: border-box; padding: 0px 5px;">60</li><li style="box-sizing: border-box; padding: 0px 5px;">61</li><li style="box-sizing: border-box; padding: 0px 5px;">62</li><li style="box-sizing: border-box; padding: 0px 5px;">63</li><li style="box-sizing: border-box; padding: 0px 5px;">64</li></ul>
这样之后,训练的数据就准备好了。
训练网络
上面的这些步骤之后,数据就已经处理好了,现在需要指定网络的超参数:
具体超参数设置如下:
<code class="hljs http has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-attribute" style="box-sizing: border-box;">net</span>: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"FaceRecognition/try5_2/train_val.prototxt"</span> <span class="hljs-attribute" style="box-sizing: border-box;">test_iter</span>: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">100</span> <span class="hljs-attribute" style="box-sizing: border-box;">test_interval</span>: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">1000</span> <span class="http" style="box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box;">base_lr</span>: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">0.001</span> <span class="hljs-attribute" style="box-sizing: border-box;">lr_policy</span>: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"step"</span> <span class="hljs-attribute" style="box-sizing: border-box;">gamma</span>: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">0.95</span> <span class="hljs-attribute" style="box-sizing: border-box;">stepsize</span>: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;"> 100000</span> <span class="hljs-attribute" style="box-sizing: border-box;">momentum</span>: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">0.9</span> <span class="hljs-attribute" style="box-sizing: border-box;">weight_decay</span>: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">0.0005</span> <span class="avrasm" style="box-sizing: border-box;"><span class="hljs-label" style="box-sizing: border-box;">display:</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">100</span> <span class="hljs-label" style="box-sizing: border-box;">max_iter:</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5000000</span> <span class="hljs-label" style="box-sizing: border-box;">snapshot:</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">50000</span> <span class="hljs-label" style="box-sizing: border-box;">snapshot_prefix:</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/media/crw/MyBook/Model/FaceRecognition/try5_2/snapshot"</span> <span class="hljs-label" style="box-sizing: border-box;">solver_mode:</span> GPU <span class="hljs-label" style="box-sizing: border-box;">device_id:</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#debug_info: true</span></span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li></ul>
一切就绪之后,开始训练网络
<code class="hljs bash has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-shebang" style="color: rgb(0, 102, 102); box-sizing: border-box;">#!/usr/bin/env sh </span> TOOLS=./build/tools GLOG_logtostderr=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> GLOG_log_dir=FaceRecognition/try5_2/Log/ \ <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$TOOLS</span>/caffe train \ --solver=FaceRecognition/try5_2/solver.prototxt <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># \</span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># --snapshot=/media/crw/MyBook/Model/FaceRecognition/try5_2/snapshot_iter_1100000.solverstate</span> </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li></ul>
训练的时候,可以查看学习曲线:
6.LFW上测试
LFW上,提供了6000对的人脸图像对来作为评测数据,由于我采用的是自己选的人脸检测和对齐方法,所以有些人脸在我的预处理里面丢失了(检测不到),为了简单的处理这种情况,在提特征的时候,没有检测到的图像就用原来的图像去替代。
<code class="hljs python has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#!/usr/bin/env python</span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># -*- coding: utf-8 -*-</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">import</span> os <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">import</span> os.path <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">def</span> <span class="hljs-title" style="box-sizing: border-box;">replace_miss</span><span class="hljs-params" style="color: rgb(102, 0, 102); box-sizing: border-box;">(filelist, src_path, substitude_path)</span>:</span> fid = open(filelist,<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'r'</span>) lines = fid.readlines() fid.close() fid = open(filelist,<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'w'</span>) count = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> line <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> lines: <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">not</span> os.path.isfile(line.strip()): <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">print</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'file :'</span>+line +<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'missed'</span> count=count+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> line=line.replace(src_path,substitude_path) fid.write(line) fid.close() <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">print</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'Totally '</span>+str(count)+<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">' file missed'</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> __name__== <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'__main__'</span>: filelist=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'/media/crw/MyBook/Evaluate/LFW_Test_List/right.list'</span> src_path = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'/media/crw/MyBook/MyDataset/LFW/croped/lfw-funneled'</span> substitude_path = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'/media/crw/DataCenter/Dataset/LFW/lfw-funneled_croped'</span> replace_miss(filelist, src_path, substitude_path)</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li></ul>
然后进行人脸的比对
<code class="hljs python has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># -*- coding: utf-8 -*-</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">""" Created on Mon Apr 20 16:55:55 2015 @author: 陈日伟 <riwei.chen@outlook.com> @brief:在lfw数据库上验证训练好了的网络 """</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">import</span> sklearn <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">import</span> numpy <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">as</span> np <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">import</span> matplotlib.pyplot <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">as</span> plt <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">import</span> skimage caffe_root = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'/home/crw/caffe-master/'</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">import</span> sys sys.path.insert(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>, caffe_root + <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'python'</span>) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">import</span> caffe <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">import</span> sklearn.metrics.pairwise <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">as</span> pw <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">def</span> <span class="hljs-title" style="box-sizing: border-box;">read_imagelist</span><span class="hljs-params" style="color: rgb(102, 0, 102); box-sizing: border-box;">(filelist)</span>:</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">''' @brief:从列表文件中,读取图像数据到矩阵文件中 @param: filelist 图像列表文件 @return :4D 的矩阵 '''</span> fid=open(filelist) lines=fid.readlines() test_num=len(lines) fid.close() X=np.empty((test_num,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64</span>)) i =<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> line <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> lines: word=line.split(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'\n'</span>) filename=word[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>] im1=skimage.io.imread(filename,as_grey=<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">False</span>) image =skimage.transform.resize(im1,(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64</span>))*<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> image.ndim<<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>: <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">print</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'gray:'</span>+filename X[i,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>,:,:]=image[:,:] X[i,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>,:,:]=image[:,:] X[i,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,:,:]=image[:,:] <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span>: X[i,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>,:,:]=image[:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>] X[i,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>,:,:]=image[:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>] X[i,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,:,:]=image[:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>] i=i+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> X <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">def</span> <span class="hljs-title" style="box-sizing: border-box;">read_labels</span><span class="hljs-params" style="color: rgb(102, 0, 102); box-sizing: border-box;">(labelfile)</span>:</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">''' 读取标签列表文件 '''</span> fin=open(labelfile) lines=fin.readlines() labels=np.empty((len(lines),)) k=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> line <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> lines: labels[k]=int(line) k=k+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>; fin.close() <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> labels <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">def</span> <span class="hljs-title" style="box-sizing: border-box;">draw_roc_curve</span><span class="hljs-params" style="color: rgb(102, 0, 102); box-sizing: border-box;">(fpr,tpr,title=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'cosine'</span>,save_name=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'roc_lfw'</span>)</span>:</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">''' 画ROC曲线图 '''</span> plt.figure() plt.plot(fpr, tpr) plt.plot([<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>], [<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>], <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'k--'</span>) plt.xlim([<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.0</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1.0</span>]) plt.ylim([<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.0</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1.0</span>]) plt.xlabel(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'False Positive Rate'</span>) plt.ylabel(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'True Positive Rate'</span>) plt.title(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'Receiver operating characteristic using: '</span>+title) plt.legend(loc=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"lower right"</span>) plt.show() plt.savefig(save_name+<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'.png'</span>) <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">def</span> <span class="hljs-title" style="box-sizing: border-box;">evaluate</span><span class="hljs-params" style="color: rgb(102, 0, 102); box-sizing: border-box;">(itera=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">500000</span>,metric=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'cosine'</span>)</span>:</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">''' @brief: 评测模型的性能 @param:itera: 模型的迭代次数 @param:metric: 度量的方法 '''</span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># 转换均值图像数据 -->npy格式文件</span> fin=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'/media/crw/MyBook/TrainData/LMDB/CASIA-WebFace/10575_64X64/mean.binaryproto'</span> fout=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'/media/crw/MyBook/TrainData/LMDB/CASIA-WebFace/10575_64X64/mean.npy'</span> blob = caffe.proto.caffe_pb2.BlobProto() data = open( fin , <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'rb'</span> ).read() blob.ParseFromString(data) arr = np.array( caffe.io.blobproto_to_array(blob) ) out = arr[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>] np.save( fout , out ) <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#设置为gpu格式</span> caffe.set_mode_gpu() net = caffe.Classifier(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'/home/crw/caffe-master/FaceRecognition/try5_2/deploy.prototxt'</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'/media/crw/MyBook/Model/FaceRecognition/try5_2/snapshot_iter_'</span>+str(itera)+<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'.caffemodel'</span>, mean=np.load(fout)) <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#需要对比的图像,一一对应</span> filelist_left=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'./LFW_Test_List/left.list'</span> filelist_right=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'./LFW_Test_List/right.list'</span> filelist_label=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'./LFW_Test_List/label.list'</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">print</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'network input :'</span> ,net.inputs <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">print</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'network output: '</span>, net.outputs <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#提取左半部分的特征</span> X=read_imagelist(filelist_left) test_num=np.shape(X)[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>] <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#data_1 是输入层的名字</span> out = net.forward_all(data_1 = X) feature1 = np.float64(out[<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'deepid_1'</span>]) feature1=np.reshape(feature1,(test_num,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">160</span>)) <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#np.savetxt('feature1.txt', feature1, delimiter=',')</span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#提取右半部分的特征</span> X=read_imagelist(filelist_right) out = net.forward_all(data_1=X) feature2 = np.float64(out[<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'deepid_1'</span>]) feature2=np.reshape(feature2,(test_num,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">160</span>)) <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#np.savetxt('feature2.txt', feature2, delimiter=',')</span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#提取标签 </span> labels=read_labels(filelist_label) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">assert</span>(len(labels)==test_num) <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#计算每个特征之间的距离</span> mt=pw.pairwise_distances(feature1, feature2, metric=metric) predicts=np.empty((test_num,)) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> i <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> range(test_num): predicts[i]=mt[i][i] <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># 距离需要归一化到0--1,与标签0-1匹配</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> i <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> range(test_num): predicts[i]=(predicts[i]-np.min(predicts))/(np.max(predicts)-np.min(predicts)) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">print</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'accuracy is :'</span>,calculate_accuracy(predicts,labels,test_num) np.savetxt(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'predict.txt'</span>,predicts) fpr, tpr, thresholds=sklearn.metrics.roc_curve(labels,predicts) draw_roc_curve(fpr,tpr,title=metric,save_name=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'lfw_'</span>+str(itera)) <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">def</span> <span class="hljs-title" style="box-sizing: border-box;">calculate_accuracy</span><span class="hljs-params" style="color: rgb(102, 0, 102); box-sizing: border-box;">(distance,labels,num)</span>:</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">''' #计算识别率, 选取阈值,计算识别率 '''</span> accuracy = [] predict = np.empty((num,)) threshold = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.2</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">while</span> threshold <= <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.8</span> : <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> i <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> range(num): <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> distance[i] >= threshold: predict[i] =<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span>: predict[i] =<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> predict_right =<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.0</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> i <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> range(num): <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> predict[i]==labels[i]: predict_right = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1.0</span>+predict_right current_accuracy = (predict_right/num) accuracy.append(current_accuracy) threshold=threshold+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.001</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> np.max(accuracy) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> __name__==<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'__main__'</span>: itera=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">500000</span> metric=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'cosine'</span> evaluate(itera,metric)</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li><li style="box-sizing: border-box; padding: 0px 5px;">54</li><li style="box-sizing: border-box; padding: 0px 5px;">55</li><li style="box-sizing: border-box; padding: 0px 5px;">56</li><li style="box-sizing: border-box; padding: 0px 5px;">57</li><li style="box-sizing: border-box; padding: 0px 5px;">58</li><li style="box-sizing: border-box; padding: 0px 5px;">59</li><li style="box-sizing: border-box; padding: 0px 5px;">60</li><li style="box-sizing: border-box; padding: 0px 5px;">61</li><li style="box-sizing: border-box; padding: 0px 5px;">62</li><li style="box-sizing: border-box; padding: 0px 5px;">63</li><li style="box-sizing: border-box; padding: 0px 5px;">64</li><li style="box-sizing: border-box; padding: 0px 5px;">65</li><li style="box-sizing: border-box; padding: 0px 5px;">66</li><li style="box-sizing: border-box; padding: 0px 5px;">67</li><li style="box-sizing: border-box; padding: 0px 5px;">68</li><li style="box-sizing: border-box; padding: 0px 5px;">69</li><li style="box-sizing: border-box; padding: 0px 5px;">70</li><li style="box-sizing: border-box; padding: 0px 5px;">71</li><li style="box-sizing: border-box; padding: 0px 5px;">72</li><li style="box-sizing: border-box; padding: 0px 5px;">73</li><li style="box-sizing: border-box; padding: 0px 5px;">74</li><li style="box-sizing: border-box; padding: 0px 5px;">75</li><li style="box-sizing: border-box; padding: 0px 5px;">76</li><li style="box-sizing: border-box; padding: 0px 5px;">77</li><li style="box-sizing: border-box; padding: 0px 5px;">78</li><li style="box-sizing: border-box; padding: 0px 5px;">79</li><li style="box-sizing: border-box; padding: 0px 5px;">80</li><li style="box-sizing: border-box; padding: 0px 5px;">81</li><li style="box-sizing: border-box; padding: 0px 5px;">82</li><li style="box-sizing: border-box; padding: 0px 5px;">83</li><li style="box-sizing: border-box; padding: 0px 5px;">84</li><li style="box-sizing: border-box; padding: 0px 5px;">85</li><li style="box-sizing: border-box; padding: 0px 5px;">86</li><li style="box-sizing: border-box; padding: 0px 5px;">87</li><li style="box-sizing: border-box; padding: 0px 5px;">88</li><li style="box-sizing: border-box; padding: 0px 5px;">89</li><li style="box-sizing: border-box; padding: 0px 5px;">90</li><li style="box-sizing: border-box; padding: 0px 5px;">91</li><li style="box-sizing: border-box; padding: 0px 5px;">92</li><li style="box-sizing: border-box; padding: 0px 5px;">93</li><li style="box-sizing: border-box; padding: 0px 5px;">94</li><li style="box-sizing: border-box; padding: 0px 5px;">95</li><li style="box-sizing: border-box; padding: 0px 5px;">96</li><li style="box-sizing: border-box; padding: 0px 5px;">97</li><li style="box-sizing: border-box; padding: 0px 5px;">98</li><li style="box-sizing: border-box; padding: 0px 5px;">99</li><li style="box-sizing: border-box; padding: 0px 5px;">100</li><li style="box-sizing: border-box; padding: 0px 5px;">101</li><li style="box-sizing: border-box; padding: 0px 5px;">102</li><li style="box-sizing: border-box; padding: 0px 5px;">103</li><li style="box-sizing: border-box; padding: 0px 5px;">104</li><li style="box-sizing: border-box; padding: 0px 5px;">105</li><li style="box-sizing: border-box; padding: 0px 5px;">106</li><li style="box-sizing: border-box; padding: 0px 5px;">107</li><li style="box-sizing: border-box; padding: 0px 5px;">108</li><li style="box-sizing: border-box; padding: 0px 5px;">109</li><li style="box-sizing: border-box; padding: 0px 5px;">110</li><li style="box-sizing: border-box; padding: 0px 5px;">111</li><li style="box-sizing: border-box; padding: 0px 5px;">112</li><li style="box-sizing: border-box; padding: 0px 5px;">113</li><li style="box-sizing: border-box; padding: 0px 5px;">114</li><li style="box-sizing: border-box; padding: 0px 5px;">115</li><li style="box-sizing: border-box; padding: 0px 5px;">116</li><li style="box-sizing: border-box; padding: 0px 5px;">117</li><li style="box-sizing: border-box; padding: 0px 5px;">118</li><li style="box-sizing: border-box; padding: 0px 5px;">119</li><li style="box-sizing: border-box; padding: 0px 5px;">120</li><li style="box-sizing: border-box; padding: 0px 5px;">121</li><li style="box-sizing: border-box; padding: 0px 5px;">122</li><li style="box-sizing: border-box; padding: 0px 5px;">123</li><li style="box-sizing: border-box; padding: 0px 5px;">124</li><li style="box-sizing: border-box; padding: 0px 5px;">125</li><li style="box-sizing: border-box; padding: 0px 5px;">126</li><li style="box-sizing: border-box; padding: 0px 5px;">127</li><li style="box-sizing: border-box; padding: 0px 5px;">128</li><li style="box-sizing: border-box; padding: 0px 5px;">129</li><li style="box-sizing: border-box; padding: 0px 5px;">130</li><li style="box-sizing: border-box; padding: 0px 5px;">131</li><li style="box-sizing: border-box; padding: 0px 5px;">132</li><li style="box-sizing: border-box; padding: 0px 5px;">133</li><li style="box-sizing: border-box; padding: 0px 5px;">134</li><li style="box-sizing: border-box; padding: 0px 5px;">135</li><li style="box-sizing: border-box; padding: 0px 5px;">136</li><li style="box-sizing: border-box; padding: 0px 5px;">137</li><li style="box-sizing: border-box; padding: 0px 5px;">138</li><li style="box-sizing: border-box; padding: 0px 5px;">139</li><li style="box-sizing: border-box; padding: 0px 5px;">140</li><li style="box-sizing: border-box; padding: 0px 5px;">141</li><li style="box-sizing: border-box; padding: 0px 5px;">142</li><li style="box-sizing: border-box; padding: 0px 5px;">143</li><li style="box-sizing: border-box; padding: 0px 5px;">144</li><li style="box-sizing: border-box; padding: 0px 5px;">145</li><li style="box-sizing: border-box; padding: 0px 5px;">146</li><li style="box-sizing: border-box; padding: 0px 5px;">147</li><li style="box-sizing: border-box; padding: 0px 5px;">148</li><li style="box-sizing: border-box; padding: 0px 5px;">149</li><li style="box-sizing: border-box; padding: 0px 5px;">150</li><li style="box-sizing: border-box; padding: 0px 5px;">151</li><li style="box-sizing: border-box; padding: 0px 5px;">152</li><li style="box-sizing: border-box; padding: 0px 5px;">153</li><li style="box-sizing: border-box; padding: 0px 5px;">154</li><li style="box-sizing: border-box; padding: 0px 5px;">155</li><li style="box-sizing: border-box; padding: 0px 5px;">156</li><li style="box-sizing: border-box; padding: 0px 5px;">157</li><li style="box-sizing: border-box; padding: 0px 5px;">158</li><li style="box-sizing: border-box; padding: 0px 5px;">159</li><li style="box-sizing: border-box; padding: 0px 5px;">160</li><li style="box-sizing: border-box; padding: 0px 5px;">161</li><li style="box-sizing: border-box; padding: 0px 5px;">162</li><li style="box-sizing: border-box; padding: 0px 5px;">163</li><li style="box-sizing: border-box; padding: 0px 5px;">164</li><li style="box-sizing: border-box; padding: 0px 5px;">165</li></ul>
结果ROC曲线:
通过选择合适的脚本,得到的准确度为:0.826333333333, 有点低。
7.结果分析
实验的结果没有理想中的那么好,主要的原因分为几个:
1、数据集不够好:有较多的噪声数据
2、数据集合不平衡:每个人的图片个数从几十张到几百张不等。
3,、网络结构没优化:原始的DeepID的大小为:48*48,而我选择的人脸图像大小为64*64,网络结构却没有相对应的调整。(主要影响在于全连接层的个数太多了)