You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dface/README.md

176 lines
6.6 KiB

7 years ago
<div align=center>
<img src="http://affluent.oss-cn-hangzhou.aliyuncs.com/html/images/dface_logo.png" width="350">
</div>
-----------------
7 years ago
# DFace • [![License](http://pic.dface.io/apache2.svg)](https://opensource.org/licenses/Apache-2.0)
7 years ago
| **`Linux CPU`** | **`Linux GPU`** | **`Mac OS CPU`** | **`Windows CPU`** |
|-----------------|---------------------|------------------|-------------------|
| [![Build Status](http://pic.dface.io/pass.svg)](http://pic.dface.io/pass.svg) | [![Build Status](http://pic.dface.io/pass.svg)](http://pic.dface.io/pass.svg) | [![Build Status](http://pic.dface.io/pass.svg)](http://pic.dface.io/pass.svg) | [![Build Status](http://pic.dface.io/pass.svg)](http://pic.dface.io/pass.svg) |
**基于多任务卷积网络(MTCNN)和Center-Loss的多人实时人脸检测和人脸识别系统。**
7 years ago
[Github项目地址](https://github.com/kuaikuaikim/DFace)
7 years ago
[Slack 聊天组](https://dfaceio.slack.com/)
7 years ago
7 years ago
**DFace** 是个开源的深度学习人脸检测和人脸识别系统。所有功能都采用 **[pytorch](https://github.com/pytorch/pytorch)** 框架开发。pytorch是一个由facebook开发的深度学习框架它包含了一些比较有趣的高级特性例如自动求导动态构图等。DFace天然的继承了这些优点使得它的训练过程可以更加简单方便并且实现的代码可以更加清晰易懂。
DFace可以利用CUDA来支持GPU加速模式。我们建议尝试linux GPU这种模式它几乎可以实现实时的效果。
所有的灵感都来源于学术界最近的一些研究成果,例如 [Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Networks](https://arxiv.org/abs/1604.02878) 和 [FaceNet: A Unified Embedding for Face Recognition and Clustering](https://arxiv.org/abs/1503.03832)
**MTCNN 结构**  
![mtcnn](http://affluent.oss-cn-hangzhou.aliyuncs.com/html/images/mtcnn_st.png)
** 如果你对DFace感兴趣并且想参与到这个项目中, 以下TODO是一些需要实现的功能我定期会更新它会实时展示一些需要开发的清单。提交你的fork request,我会用issues来跟踪和反馈所有的问题。也可以加DFace的官方Q群 681403076 也可以加本人微信 jinkuaikuai005 **
7 years ago
### TODO(需要开发的功能)
- 基于center loss 或者triplet loss原理开发人脸对比功能模型采用ResNet inception v2. 该功能能够比较两张人脸图片的相似性。具体可以参考 [Paper](https://arxiv.org/abs/1503.03832)和[FaceNet](https://github.com/davidsandberg/facenet)
- 反欺诈功能根据光线质地等人脸特性来防止照片攻击视频攻击回放攻击等。具体可参考LBP算法和SVM训练模型。
- 3D人脸反欺诈。
- mobile移植根据ONNX标准把pytorch训练好的模型迁移到caffe2,一些numpy算法改用c++实现。
7 years ago
- Tensor RT移植高并发。
- Docker支持gpu版
7 years ago
## 安装
7 years ago
DFace主要有两大模块人脸检测和人脸识别。我会提供所有模型训练和运行的详细步骤。你首先需要构建一个pytorch和cv2的python环境我推荐使用Anaconda来设置一个独立的虚拟环境。目前作者倾向于Linux Ubuntu安装环境。感谢山东一位网友提供windows DFace安装体验windos安装教程具体
可参考他的[博客](http://www.alearner.top/index.php/2017/12/23/dface-pytorch-win64-gpu)
7 years ago
### 依赖
* cuda 8.0
* anaconda
* pytorch
* torchvision
* cv2
* matplotlib
```shell
git clone https://gitee.com/kuaikuaikim/dface.git
```
7 years ago
在这里我提供了一个anaconda的环境依赖文件environment.yml windows请用environment-win64.yml它能方便你构建自己的虚拟环境。
7 years ago
```shell
7 years ago
cd dface
conda env create -f environment.yml
7 years ago
```
添加python搜索模块路径
```shell
export PYTHONPATH=$PYTHONPATH:{your local DFace root path}
```
### 人脸识别和检测
7 years ago
如果你对mtcnn模型感兴趣以下过程可能会帮助到你。
#### 训练mtcnn模型
MTCNN主要有三个网络叫做**PNet**, **RNet****ONet**。因此我们的训练过程也需要分三步先后进行。为了更好的实现效果,当前被训练的网络都将依赖于上一个训练好的网络来生成数据。所有的人脸数据集都来自 **[WIDER FACE](http://mmlab.ie.cuhk.edu.hk/projects/WIDERFace/)** 和 **[CelebA](http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html)**。WIDER FACE仅提供了大量的人脸边框定位数据而CelebA包含了人脸关键点定位数据。以下训练除了 生成ONet的人脸关键点训练数据和标注文件 该步骤使用CelebA数据集其他一律使用WIDER FACE。如果使用wider face的 wider_face_train.mat 注解文件需要转换成txt格式的我这里用h5py写了个 [转换脚本](https://gitee.com/kuaikuaikim/dface/blob/master/src/prepare_data/widerface_annotation_gen/transform.py)
7 years ago
* 生成PNet训练数据和标注文件
```shell
python dface/prepare_data/gen_Pnet_train_data.py --dataset_path {your dataset path} --anno_file {your dataset original annotation path}
7 years ago
```
* 乱序合并标注文件
```shell
python dface/prepare_data/assemble_pnet_imglist.py
7 years ago
```
* 训练PNet模型
```shell
python dface/train_net/train_p_net.py
7 years ago
```
* 生成Net训练数据和标注文件
```shell
python dface/prepare_data/gen_Rnet_train_data.py --dataset_path {your dataset path} --anno_file {your dataset original annotation path} --pmodel_file {yout PNet model file trained before}
7 years ago
```
* 乱序合并标注文件
```shell
python dface/prepare_data/assemble_rnet_imglist.py
7 years ago
```
* 训练RNet模型
```shell
python dface/train_net/train_r_net.py
7 years ago
```
* 生成ONet训练数据和标注文件
```shell
python dface/prepare_data/gen_Onet_train_data.py --dataset_path {your dataset path} --anno_file {your dataset original annotation path} --pmodel_file {yout PNet model file trained before} --rmodel_file {yout RNet model file trained before}
7 years ago
```
* 生成ONet的人脸关键点训练数据和标注文件
```shell
python dface/prepare_data/gen_landmark_48.py
7 years ago
```
* 乱序合并标注文件(包括人脸关键点)
```shell
python dface/prepare_data/assemble_onet_imglist.py
7 years ago
```
* 训练ONet模型
```shell
python dface/train_net/train_o_net.py
7 years ago
```
#### 测试人脸检测
```shell
python test_image.py
```
### 人脸对比
7 years ago
7 years ago
@TODO 根据center loss实现人脸识别
7 years ago
7 years ago
## 测试效果
7 years ago
![mtcnn](http://affluent.oss-cn-hangzhou.aliyuncs.com/html/images/dface_demoall.PNG)
7 years ago
7 years ago
7 years ago
### QQ交流群(模型获取请加群)
7 years ago
#### 681403076
7 years ago
![](http://affluent.oss-cn-hangzhou.aliyuncs.com/html/images/dfaceqqsm.png)
7 years ago
#### 本人微信
##### jinkuaikuai005
![](http://affluent.oss-cn-hangzhou.aliyuncs.com/html/images/perqr.jpg)
7 years ago
## License
[Apache License 2.0](LICENSE)