转载自 https://blog.csdn.net/qq_35975447/article/details/110430390
【人脸检测】 Tinaface复现(数据集准备、测试与评估)
参考:
TinaFace: Strong but Simple Baseline for Face Detection
https://github.com/Media-Smart/vedadet
https://github.com/sovrasov/wider-face-pascal-voc-annotations
0.环境
-
ubuntu16.04
-
python3.6
-
cuda9.2
-
cudnn7
-
torch==1.6.0+cu92
-
addict==2.4.0
-
cycler==0.10.0
-
Cython==0.29.21
-
future==0.18.2
-
kiwisolver==1.3.1
-
matplotlib==3.3.3
-
numpy==1.19.4
-
Pillow==8.0.1
-
pycurl==7.43.0
-
pygobject==3.20.0
-
pyparsing==2.4.7
-
python-apt==1.1.0b1+ubuntu0.16.4.9
-
python-dateutil==2.8.1
-
six==1.15.0
-
unattended-upgrades==0.1
-
tqdm
-
scipy
-
ipython
-
cd vedadet
-
pip install -r requirements/build.txt
避免出错,我直接安装环境中对应的python库,然后注释掉对应的根目录下setup.py中的安装依赖包的两行。
改为:
(默认会安装最新的,如果对应的cuda版本不支持的话,那就自己安装吧!!!)然后执行下面:
pip install -v -e .
1.准备
1.1 准备模型
https://drive.google.com/u/0/uc?id=1zU738coEVDBkLBUa4hvJUucL7dcSBT7v&export=download
可以将放到https://github.com/Media-Smart/vedadet/tree/main/configs/trainval/tinaface,目录下新建的models下。
1.2 准备数据
1)原始数据
https://github.com/Media-Smart/vedadet/tree/main/configs/trainval/tinaface
进入vedadet/目录下,新建data,然后进入data目录下,从widerface官网上下载训练、验证与测试数据:
解压从官网下载的数据,目录应该是这样:
-
vedadet
-
├── vedadet
-
├── vedacore
-
├── tools
-
├── configs
-
├── data
-
│ ├── WIDERFace
-
│ │ ├── WIDER_train
-
│ │ │ ├── images
-
│ │ │ │ ├── 0--Parade
-
│ │ │ │ ├── ......
-
│ │ │ │ ├── 61--Street_Battle
-
│ │ ├── WIDER_val
-
│ │ │ ├── images
-
│ │ │ │ ├── 0--Parade
-
│ │ │ │ ├── ......
-
│ │ │ │ ├── 61--Street_Battle
-
│ │ ├── WIDER_test
-
│ │ ├── wider_face_split
2)xml文件
下载对应的VOC格式的xml文件:
-
git clone https://github.com/sovrasov/wider-face-pascal-voc-annotations.git
-
cd vedadet/data
-
mv wider-face-pascal-voc-annotations/ WIDERFace/
-
mv WIDERFace/WIDER_train_annotations WIDERFace/WIDER_train/Annotations
-
mv WIDERFace/WIDER_val_annotations WIDERFace/WIDER_val/Annotations
然后利用命令:
-
cd ..
-
sh configs/trainval/tinaface/gen_xml_name_txt.sh
目录结构如下:
-
vedadet
-
├── vedadet
-
├── vedacore
-
├── tools
-
├── configs
-
├── data
-
│ ├── WIDERFace
-
│ │ ├── WIDER_train
-
│ │ │ ├── images
-
│ │ │ │ ├── 0--Parade
-
│ │ │ │ ├── ......
-
│ │ │ │ ├── 61--Street_Battle
-
│ │ │ ├── Annotations
-
│ │ ├── WIDER_val
-
│ │ │ ├── images
-
│ │ │ │ ├── 0--Parade
-
│ │ │ │ ├── ......
-
│ │ │ │ ├── 61--Street_Battle
-
│ │ │ ├── Annotations
-
│ │ ├── WIDER_test
-
│ │ ├── wider_face_split
3)代码中路径等修改
由于与作者给出的目录略微有点不同,所以修改以下:
-
# \vedadet\configs\trainval\tinaface\tinaface.py line 14与38
-
img_prefix=data_root + 'WIDER_train/',
-
img_prefix=data_root + 'WIDER_val/',
-
改为:
-
img_prefix=data_root + 'WIDER_train/images/',
-
img_prefix=data_root + 'WIDER_val/images/',
-
# \vedadet\vedadet\datasets\widerface.py line 36-37
-
xml_path = osp.join(self.img_prefix, 'Annotations',
-
f'{img_id}.xml')
-
改为
-
xml_path = osp.join(self.img_prefix.replace('images','Annotations'),
f'{img_id}.xml')
将/vedadet/vedadet/datasets/xml_style.py
其中 \vedadet\vedadet\datasets\xml_style.py 中对应的xml_path也要修改为相应的
-
xml_path = osp.join(self.img_prefix, 'Annotations',
-
f'{img_id}.xml')
-
改为
-
xml_path = osp.join(self.img_prefix.replace('images','Annotations'),
-
f'{img_id}.xml')
至此,基本就可以了。如果想修改数据的根目录:
-
# \vedadet\configs\trainval\tinaface\tinaface.py line 3 改为你对应的对应就可以了,绝对与相对路径都可以
-
data_root = './data/WIDERFace/'
2.测试与评估
2.1 测试
python configs/trainval/tinaface/test_widerface.py configs/trainval/tinaface/tinaface.py /root/vedadet/weights/tinaface_r50_fpn_widerface.pth
会在vedadet/eval_dirs/tmp/tinaface/目录下,生成对应的txt文件。
2.2 评估
还是用之前很多篇评估widerface的方式来评估一下。
将Pytorch_Retinaface/widerface_evaluate内的这几个文件与widerface_eval文件夹,复制到vedadet/tools目录下。
https://github.com/biubug6/Pytorch_Retinaface/tree/master/widerface_evaluate
https://github.com/ChiCheng123/SRN/tree/master/tools
widerface_eval文件也可以在我的资源中下载:https://download.csdn.net/download/qq_35975447/14158058
命令加修改:
-
cd ./tools
-
python setup.py build_ext --inplace
-
vim evaluation.py
-
# line 287-288
-
parser.add_argument('-p', '--pred', default="${vedadet_root}/eval_dirs/tmp/tinaface/")
-
parser.add_argument('-g', '--gt', default='./widerface_eval/ground_truth/')
-
python evaluation.py
其中参数:
--pred是预测结果txt文件的保存路径,默认为:
--gt是真实的,我们之前准备的。
2.3 评估结果
评估结果还是比较准的,这个是没有加TTA的。