Fly paddle takes you to learn to use metrics to improve the accuracy of face recognition

small test


Presumably in everyday life, we always have a feeling that some of the people around him know, obviously there is no blood relationship, but it might look like, especially for blind students face, really silly I could not tell.

 

We have here a set of questions, to Cece everyone's face recognition level.

 

First to a simple, face recognition [four] level, who are below two male stars?


640?wx_fmt=png


Very simple is not it?

The answer should be no need unveiled

We should not beat

 

Build on the progress we come to a recognition [six], the following two are female star who is?


640?wx_fmt=png


Is estimated to have some people can not answer the

Of course, most likely reason is that

You do not know who is left


The answer here is not announced, interested can try our Baidu knowledge map: http://image.baidu.com/?fr=shitu, you will be able to tell you a satisfactory answer.

 

Some readers must have felt, know the result of the above two questions is very easy ah, well, next question.


Our face recognition finale [eight] coming!

 

Indefinite term multiple-choice questions


The following nine photographs, assuming left to right, according to the order is 1-3,4-6,7-9, then, and 2 photos of the same person is the date? ()


A, No. 3 B, No. 4 C, No. 5 D, No. 9


640?wx_fmt=png

Announced answer

No!

The above photo was nine nine people! !

It is not unexpected is not?

Yes


In some special cases, the face recognition in humans has quickly become the Impossible mission.


The introduction of a measure of learning


With face recognition technology gradually assume an increasingly important role in the identity verification, access control access, airport security, financial services, etc. areas for the accuracy of high demands, how to be more precise, distinguishing samples has become enormous challenges face recognition technology.

 

2002年,Eric Xing在NIPS2002提出度量学习 (Metric Learning)的概念。其中度量在数学中的定义为:一个度量(或距离函数)是一个定义集合中元素之间距离的函数。一个具有度量的集合被称为度量空间。常见的度量算法如下表所示。


640?wx_fmt=png


度量学习目的是在特征空间中,让同一个类别的样本具有较小的特征距离,不同类的样本具有较大的特征距离。算法越来越依赖于在输入空间给定的好的度量。

 

假设我们需要计算图像之间的相似度(或距离),例如识别人脸时,我们需要构建一个距离函数去强化合适的特征(如脸型,五官等);而如果我们想识别姿势,就需要构建一个捕获姿势相似度的距离函数(如关节,动作)。为了处理各种各样的特征相似度,我们需要在特定的任务选择合适的特征并手动构建距离函数。这种方法会需要很大的人工投入,也可能对数据的改变非常不鲁棒。

 

度量学习作为一个理想的替代,可以根据不同的任务来自主学习出针对某个特定任务的度量距离函数。随着深度学习技术的发展,基于深度神经网络的度量学习方法极大的推动了人脸识别、人脸校验、行人重识别和图像检索等众多计算机视觉任务的性能提升。

 

飞桨的深度度量学习实现

 

在本章节,我们将为大家介绍在飞桨里实现的几种度量学习方法和使用方法,具体包括数据准备,模型训练,模型微调,模型评估,模型预测。


安装与依赖


运行本章节代码需要在Paddle Fluid v0.14.0 或更高的版本环境。如果你的设备上的Paddle Fluid版本低于v0.14.0,请及时安装和更新。

 

数据准备


Stanford Online Product(SOP) 数据集下载自eBay,包含120053张商品图片,有22634个类别。我们使用该数据集进行实验。训练时,使用59551张图片,11318个类别的数据;测试时,使用60502张图片,11316个类别。


SOP数据集的ftp网址:

ftp://cs.stanford.edu/cs/cvgl/Stanford_Online_Products.zip。


如果下载速度太慢,也可以到百度AI Studio公开数据集里面下载:

https://aistudio.baidu.com/aistudio/datasetDetail/5103


模型训练


为了训练度量学习模型,首先,我们需要选择一个神经网络模型作为骨架模型(例如ResNet50),其次,我们选择一个代价函数来进行训练(例如softmax 或者 arcmargin)。举例如下:

 
  
python train_elem.py  \	
        --model=ResNet50 \	
        --train_batch_size=256 \	
        --test_batch_size=50 \	
        --lr=0.01 \	
        --total_iter_num=30000 \	
        --use_gpu=True \	
        --pretrained_model=${path_to_pretrain_imagenet_model} \	
        --model_save_dir=${output_model_path} \	
        --loss_name=arcmargin \	
        --arc_scale=80.0 \ 	
        --arc_margin=0.15 \	
        --arc_easy_margin=False


其中,参数介绍:

  • model: 使用的模型名字. 默认:"ResNet50".

  • train_batch_size: 训练的 mini-batch大小. 默认: 256.

  • test_batch_size: 测试的 mini-batch大小. 默认: 50.

  • lr: 初始学习率. 默认:0.01.

  • total_iter_num: 总的训练迭代轮数. 默认:30000.

  • use_gpu: 是否使用GPU. 默认:True.

  • pretrained_model: 预训练模型的路径. 默认:None.

  • model_save_dir: 保存模型的路径. 默认:"output".

  • loss_name: 优化的代价函数. 默认:"softmax".

  • arc_scale: arcmargin的参数. 默认: 80.0.

  • arc_margin:arcmargin的参数. 默认: 0.15.

  • arc_easy_margin: arcmargin的参数. 默认: False.


模型微调


模型微调是在指定的任务上加载已有的模型来微调网络。在用softmax和arcmargin训完网络后,可以继续使用triplet,quadruplet或eml来微调网络。下面是一个使用eml来微调网络的例子:

 
  
python train_pair.py  \	
        --model=ResNet50 \	
        --train_batch_size=160 \	
        --test_batch_size=50 \	
        --lr=0.0001 \	
        --total_iter_num=100000 \	
        --use_gpu=True \	
        --pretrained_model=${path_to_pretrain_arcmargin_model} \	
        --model_save_dir=${output_model_path} \	
        --loss_name=eml \	
        --samples_each_class=2

其中,参数介绍同训练过程一致。

 

模型评估


模型评估主要是评估模型的检索性能。这里需要设置path_to_pretrain_model。可以使用下面命令来计算Recall@Rank-1。

 
  
python eval.py \	
       --model=ResNet50 \	
       --batch_size=50 \	
       --pretrained_model=${path_to_pretrain_model} \


模型预测


Model prediction is mainly based on image data acquired trained network characteristics, for example as follows:

 
  
python infer.py \	
       --model=ResNet50 \	
       --batch_size=1 \         	
       --pretrained_model=${path_to_pretrain_model}


Model Performance


Here are several retrieval results metric cost function learning data sets in the SOP, herein Recall @ Rank-1 to be evaluated.


640?wx_fmt=png


More details can be found in:

https://github.com/PaddlePaddle/models/tree/v1.4/PaddleCV/metric_learning

640?wx_fmt=png

Guess you like

Origin blog.csdn.net/PaddlePaddle/article/details/93377525