[Face detection] Tinaface reproduction (data set preparation, testing and evaluation)

It seems that the author has changed the code recently, so you can refer to the environment of this article if you want to reproduce it. Work around the specific details.

reference:

TinaFace: Strong but Simple Baseline for Face Detection

https://github.com/Media-Smart/vedadet

https://github.com/sovrasov/wider-face-pascal-voc-annotations

0. Environment

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

To avoid errors, I directly installed the corresponding python library in the environment, and then commented out the two lines of installation dependent packages in setup.py in the corresponding root directory.

To: 

(The latest version will be installed by default. If the corresponding cuda version does not support it, install it yourself!!!) Then execute the following:

pip install -v -e .

 

1. Preparation

1.1 Prepare the model

https://drive.google.com/u/0/uc?id=1zU738coEVDBkLBUa4hvJUucL7dcSBT7v&export=download

You can put it in https://github.com/Media-Smart/vedadet/tree/main/configs/trainval/tinaface , under the newly created models in the directory.

1.2 Prepare data

1) Raw data

https://github.com/Media-Smart/vedadet/tree/main/configs/trainval/tinaface

Enter the vedadet/ directory, create a new data, then enter the data directory, and download the training, verification and test data from the widerface official website:

 Unzip the data downloaded from the official website, the directory should look like this:

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 file

Download the corresponding VOC format xml file: 

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

 Then use the command:

cd ..
sh configs/trainval/tinaface/gen_xml_name_txt.sh

The directory structure is as follows:

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) Modifications such as the path in the code

Because it is slightly different from the directory given by the author, modify the following:

# \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')

! ! ! The corresponding xml_path in \vedadet\vedadet\datasets\xml_style.py should also be modified to the corresponding one.

At this point, it's basically all right. If you want to modify the root directory of the data:

# \vedadet\configs\trainval\tinaface\tinaface.py line 3 改为你对应的对应就可以了,绝对与相对路径都可以
data_root = './data/WIDERFace/'

2. Testing and Evaluation

2.1 Testing

python configs/trainval/tinaface/test_widerface.py configs/trainval/tinaface/tinaface.py /root/vedadet/weights/tinaface_r50_fpn_widerface.pth

The corresponding txt file will be generated in the vedadet/eval_dirs/tmp/tinaface/ directory.

2.2 Evaluation

Let's use the same way to evaluate widerface in many previous articles.

Copy these files in Pytorch_Retinaface/widerface_evaluate and the widerface_eval folder to the vedadet/tools directory.

https://github.com/biubug6/Pytorch_Retinaface/tree/master/widerface_evaluate

https://github.com/ChiCheng123/SRN/tree/master/tools

 

 The widerface_eval file can also be downloaded in my resources: https://download.csdn.net/download/qq_35975447/14158058

Command plus modification:

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

The parameters:

--pred is the save path of the prediction result txt file, the default is:

 --gt is real, we prepared before.

 

2.3 Evaluation results 

The evaluation result is quite accurate, and TTA is not added to this one.

 

 reference

1.vedadet (official code)

2.tinaface (official paper)

3. Wider-face-pascal-voc-annotations (xml file)

4. Evaluation part reference (SRN)

5. Evaluate part of the code and gt

Guess you like

Origin blog.csdn.net/qq_35975447/article/details/110430390