README.md 5.61 KB
Newer Older
chenych's avatar
chenych committed
1
2
3
4
5
6
# CenterFace
## 论文
[CenterFace: Joint Face Detection and Alignment Using Face as Point](https://arxiv.org/abs/1911.03599)

## 模型结构
CenterFace是一种人脸检测算法,采用了轻量级网络mobileNetV2作为主干网络,结合特征金字塔网络(FPN)实现anchor free的人脸检测。
chenych's avatar
chenych committed
7
8
9
<div align=center>
    <img src="./Architecture of the CenterFace.png"/>
</div>
chenych's avatar
chenych committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
## 算法原理
CenterFace模型是一种基于单阶段人脸检测算法,作者借鉴了CenterNet的思想,将人脸检测转换为标准点问题,根据人脸中心点来回归人脸框的大小和五个标志点。

## 环境配置
### Docker(方法一)

```
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk-23.04.1-py38-latest

docker run docker run -it -v /path/your_code_data/:/path/your_code_data/ --shm-size=32G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name docker_name imageID bash

cd /path/workspace/
pip3 install -r requirements.txt
```

### Dockerfile(方法二)

```
cd ./docker

docker build --no-cache -t centerface:latest .

docker run -it -v /path/your_code_data/:/path/your_code_data/ --shm-size=32G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name docker_name imageID bash
```

### Anaconda(方法三)

1、关于本项目DCU显卡所需的特殊深度学习库可从光合开发者社区下载安装: https://developer.hpccube.com/tool/

```
DTK软件栈:dtk23.04.1
python:python3.8
torch:1.13.1
torchvision:0.14.1
```
`Tips:以上dtk驱动、python、paddle等DCU相关工具版本需要严格一一对应`

2、其他非特殊库直接按照requirements.txt安装

```
pip3 install -r requirements.txt
```

## 数据集

chenych's avatar
chenych committed
55
WIDER_FACE:http://shuoyang1213.me/WIDERFACE/index.html
chenych's avatar
chenych committed
56

chenych's avatar
chenych committed
57
58
59
<div align=center>
    <img src="./datasets.png"/>
</div>
chenych's avatar
chenych committed
60
61
62
63
64
65
66
67
68
69
70
71
72

下载图片红框中三个数据并解压,也可直接点击下面链接直接下载:

[WIDER Face Training Images(Tencent Drive)](https://share.weiyun.com/5WjCBWV)

[WIDER Face Validation Images(Tencent Drive)](https://share.weiyun.com/5ot9Qv1)

[WIDER Face Testing Images(Tencent Drive)](https://share.weiyun.com/5vSUomP)


数据集全部解压后的目录结构如下:

```
chenych's avatar
chenych committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
├── wider_face:  存放数据集根目录
│   ├── WIDER_train: 训练集解压后的文件目录
│       └── images:
│           ├──  0--Parade:         对应该类别的所有图片
│           ├──  ........
│           └──  61--Street_Battle: 对应该类别的所有图片
│   ├── WIDER_val: 验证集解压后的文件目录
│       └──  images:
│           ├──  0--Parade:         对应该类别的所有图片
│           ├──  ........
│           └──  61--Street_Battle: 对应该类别的所有图片
│   ├── WIDER_test: 训练集解压后的文件目录
│       └──  images:
│           ├──  0--Parade:         对应该类别的所有图片
│           ├──  ........
│           └──  61--Street_Battle: 对应该类别的所有图片
```

解压完成后执行以下步骤:
1. 将训练图片放置于 ./datasets/images/train的目录下,验证数据放置于./datasets/images/val目录下,存放目录结如下
```
├── images
│   ├── train
│       ├── 0--Parade
│       ├──  ........
│       └──  61--Street_Battle
│   ├── val
│       ├── 0--Parade
│       ├──  ........
│       └──  61--Street_Battle
```

2. 如果是使用WIDER_train、WIDER_val数据, 可直接将./datasets/labels/下的train_wider_face.json重命名为train_face.json, val_wider_face.json重命名为val_face.json即可,无需进行标注文件格式转换;
chenych's avatar
chenych committed
106
反之,需要将训练图片/验证图片对应的人脸标注信息文件train.txt/val.txt,放置于 ./datasets/annotations/下(train存放训练图片的标注文件,val存放验证图片的标注文件),存放目录结构如下:
chenych's avatar
chenych committed
107
108

```
chenych's avatar
chenych committed
109
├── annotations
chenych's avatar
chenych committed
110
111
112
113
114
│   ├── train
│       ├── train.txt
│   ├── val
│       ├── val.txt
```
chenych's avatar
chenych committed
115

chenych's avatar
chenych committed
116
117
118
119
120
121
122
123
特别地,标注信息的格式为:

```
# img_file/image_name # #+空格+img_file/image_name
x, y, w, h, left_eye_x, left_eye_y, flag, right_eye_x, right_eye_y, flag, nose_x, nose_y, flag, left_mouth_x, left_mouth_y, flag, right_mouth_x, right_mouth_y, flag, confidence  # x和y是检测框左上角的坐标
```

举个例子:
chenych's avatar
chenych committed
124
125
./datasets/annotations/train/train.txt是wider_face训练数据集的标注信息

chenych's avatar
chenych committed
126
127
128
129
```
# 0--Parade/0_Parade_marchingband_1_849.jpg
449 330 122 149 488.906 373.643 0.0 542.089 376.442 0.0 515.031 412.83 0.0 485.174 425.893 0.0 538.357 431.491 0.0 0.82
...
chenych's avatar
chenych committed
130
131
```

chenych's avatar
chenych committed
132
133
134
135
136
137
138
139
140
141
3. 生成训练所需的json格式标注数据:

```
cd ./datasets
python gen_data.py
```

执行完成后会在./datasets/labels下生成训练数据的标注文件 train_face.json、val_face.json


chenych's avatar
chenych committed
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
## 训练
### 单机单卡

```
cd ./src
bash train.sh
```

### 单机多卡

```
cd ./src
bash train_multi.sh
```

## 推理
#### 单卡推理
chenych's avatar
chenych committed
159

chenych's avatar
chenych committed
160
161
162
163
164
165
```
cd ./src
python test_wider_face.py
```

## result
chenych's avatar
chenych committed
166
167
168
169

<div align=center>
    <img src="./draw_img.jpg"/>
</div>
chenych's avatar
chenych committed
170
171

### 精度
chenych's avatar
chenych committed
172

chenych's avatar
chenych committed
173
174
WIDER_FACE验证集上的测试结果如下

chenych's avatar
chenych committed
175
| Method | Easy(AP) | Medium(AP) | Hard(AP)|
chenych's avatar
chenych committed
176
177
178
179
180
181
182
183
184
185
186
187
188
|:--------:| :--------:| :---------:| :------:|
| ours(one scale) | 0.9264 | 0.9133 | 0.7479 |
| original | 0.922 | 0.911  | 0.782|


## 应用场景
### 算法类别
人脸识别

### 热点应用行业
教育,交通,公安,医疗

## 源码仓库及问题反馈
chenych's avatar
Add .sh  
chenych committed
189
https://developer.hpccube.com/codes/modelzoo/centerface_pytorch
chenych's avatar
chenych committed
190
191
192

## 参考资料
https://github.com/chenjun2hao/CenterFace.pytorch