【人脸检测】Tencent之FaceDetection-DSFD测试与评估复现

参考

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

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

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

0.环境

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.修改

(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)模型下载

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

(3)数据下载

http://shuoyang1213.me/WIDERFACE/ 

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

分别解压在widerface目录下,文件目录:

widerface
    wider_face_split
    WIDER_test
    WIDER_train
    WIDER_val

(4)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.测试

2.1 测试

测试大概需要7-8G显存。

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 测试结果

跟Retinaface_Pytorch中类似,都是将测试结果写到一个文件中,最后再通过之前用过的Retinaface_Pytorch中的评估对几项指标统计。

3.评估

3.1 评估

由于这里没有对应的gt(mat文件),所以这里参考SRN中,根据对应的目录结构,复制与新建对应文件。目录结构如下:

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

修改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 评估结果

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

猜你喜欢

转载自blog.csdn.net/qq_35975447/article/details/110282560