[Face Detection] Tencent's FaceDetection-DSFD test and evaluation reproduction

reference

https://paperswithcode.com/paper/dsfd-dual-shot-face-detector

https://github.com/Tencent/FaceDetection-DSFD

https://arxiv.org/pdf/1810.10220.pdf

0. Environment

ubuntu16.04
python3.6
torch==0.4.1 # (cuda90)  @ https://download.pytorch.org/whl/cu90/torch-0.4.1-cp36-cp36m-linux_x86_64.whl
cycler==0.10.0
kiwisolver==1.3.1
matplotlib==3.3.3
numpy==1.19.4
opencv-python==4.4.0.46
Pillow==8.0.1
pyparsing==2.4.7
python-dateutil==2.8.1
PyYAML==5.3.1
scipy==1.2.0
six==1.15.0
torchvision==0.2.2
tqdm==4.19.9
Cython
ipython

1. Modify

(1)ImportError: cannot import name 'pa_sfd_match'

# FaceDetection-DSFD-master\layers\modules\multibox_loss.py line 13
from ..box_utils import (log_sum_exp, match, pa_sfd_match, refine_match,
                         sfd_match)
改为
from ..box_utils import (log_sum_exp, match, sfd_match, refine_match,
                         sfd_match)

(2) Model download

https://download.pytorch.org/models/resnet152-b121ed2d.pth

(3) Data download

http://shuoyang1213.me/WIDERFACE/ 

wget http://mmlab.ie.cuhk.edu.hk/projects/WIDERFace/support/bbx_annotation/wider_face_split.zip

Decompress them in the widerface directory, the file directory:

widerface
    wider_face_split
    WIDER_test
    WIDER_train
    WIDER_val

(4) Modification of widerface_val.py

# about cuda device

# line 41 add
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

# line 230
net.load_state_dict(torch.load(args.trained_model, map_location='cpu'))
net.to(device)

# line 61-67
x = Variable(x.to(device), volatile=True)
#net.priorbox = PriorBoxLayer(width,height)
y = net(x)
detections = y.data
scale = torch.Tensor([width, height, width, height])

#改为:

with torch.no_grad():
        x = Variable(x.to(device))

        #net.priorbox = PriorBoxLayer(width,height)
        y = net(x)
        detections = y.data
        scale = torch.Tensor([width, height, width, height])
        torch.cuda.empty_cache()

2. Test

2.1 Testing

The test probably needs 7-8G video memory.

CUDA_VISIBLE_DEVICES=0 python widerface_val.py --trained_model ./weights/WIDERFace_DSFD_RES152.pth --save_folder ./results/ --widerface_root ./data/widerface/ --cuda=True

2.2 Test results

Similar to Retinaface_Pytorch, the test results are written to a file, and finally several indicators are counted through the evaluation in Retinaface_Pytorch used before.

3. Evaluation

3.1 Evaluation

Since there is no corresponding gt (mat file) here, we refer to SRN and copy and create the corresponding file according to the corresponding directory structure. The directory structure is as follows:

tools
    box_overlaps.c  #这四个文件复制自Pytorch_Retinaface
    box_overlaps.pyx  
    evaluation.py  
    setup.py 
    widerface_eval #复制自SRN
    results #复制自本方法测试后结果,在根目录下

Modify evaluation.py (line 287-288):

parser.add_argument('-p', '--pred', default="./results/")
parser.add_argument('-g', '--gt', default='./widerface_eval/ground_truth/')
cd ./tools
python setup.py build_ext --inplace

3.2 Evaluation results

cp -r results/ ./tools/
python evaluation.py

 

Guess you like

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