轻量级的人脸检测模型
简介
人脸检测现在已经被做坏了,各种算法,轻重都有,总有一款适合你,今天我们做一个轻量级的,模型大小只有580kb。
github
注意是tf2 分支
出发点
人脸检测是一类检测算法,而且目前主流的算法都是基于ssd的结构。
想要模型快,小就两点,模型参数量,模型的计算复杂度。
基于此,可以大致定下需要的模型结构
- one sage
- 轻backbone
- 输入尺寸320x320 或更小
- 输出feature不宜过大,层数不宜过多,一般3层,按需来
- 适当的提升性能的手段,例如fpn,inception等的结构
等。。。。
具体的结构见代码
于是有了 lightnet , 算是改的DSFD吧,但是更像retinanetface
github
注意是tf2 分支
模型和性能
Lightnet_0.5 including tflite model,
(time cost: mac i5-8279U@2.4GHz, tf2.0 15ms+, tflite 8ms±,input shape 320x320)
- baidu disk ( password yqst )
- google drive
model | input_size | fddb | model size |
---|---|---|---|
Lightnet_0.75 | 640x640 | 0.960 | 800k± |
Lightnet_0.5 | 640x640 | 0.953 | 560k± |
Lightnet_0.5 | 416x416 | 0.953 | 560k± |
Lightnet_0.5 | 320x320 | 0.936 | 560k± |
model | input_size | wider easy | wider medium | wider hard |
---|---|---|---|---|
Lightnet_0.75 | 640x640 | 0.867 | 0.806 | 0.440 |
Lightnet_0.5 | 640x640 | 0.858 | 0.796 | 0.430 |
Lightnet_0.5 | multiscale | 0.861 | 0.837 | 0.726 |
ps the time cost not including nms, and flip test is used
训练
- 首先clone下代码,
git clone https://github.com/610265158/DSFD-tensorflow.git
- 下载数据集widerface
把 WIDER_train, WIDER_val and wider_face_split 放到新建的WIDER 下面, - 然后运行,
python prepare_wider_data.py
, 然后会产生train.txt 和val.txt
其中 内容每一行是这个样子:./WIDER/WIDER_val/images/0–Parade/0_Parade_Parade_0_913.jpg| 238,146,450,392,1 612,192,818,426,1 28,100,104,214,1。
也就是如果 你要训练你自己的数据就这样: imgpath| xmin,ymin,xmax,ymax,1 …
-
默认的config文件是一个很轻量级的模型, 直接运行
python train.py -
模型转换 python tools/convert_to_tflite.py 会转换为tflite 模型
如果训练完了,想看一下demo,
python vis.py --model ./model/detector.tflite
or
python vis.py --model ./model/detector