Skip to content

jnulzl/Pytorch_Retinaface_To_Caffe

Repository files navigation

Update:

  • 2020-03-28 Convert mobilenet0.25_Final.pth to caffemodel

Test

  • Compile my_caffe

  • Add PATH_of_YOUR_CAFFE_PYTHON and ../ to PYTHONPATH in toCaffe/detect.py:

from __future__ import print_function
import sys
sys.path.insert(0, "PATH_of_YOUR_CAFFE_PYTHON")
sys.path.insert(1, "../")
import caffe
  • Run detect.py
cd toCaffe
python detect.py

......
I0328 21:35:30.897866 15789 net.cpp:202] BatchNorm2d_7_BN does not need backward computation.
I0328 21:35:30.897871 15789 net.cpp:202] Conv2d_6 does not need backward computation.
I0328 21:35:30.897883 15789 net.cpp:202] LeakyReLU_5 does not need backward computation.
I0328 21:35:30.897891 15789 net.cpp:202] BatchNorm2d_4_Scale does not need backward computation.
I0328 21:35:30.897897 15789 net.cpp:202] BatchNorm2d_4_BN does not need backward computation.
I0328 21:35:30.897903 15789 net.cpp:202] Conv2d_3 does not need backward computation.
I0328 21:35:30.897910 15789 net.cpp:202] LeakyReLU_2 does not need backward computation.
I0328 21:35:30.897917 15789 net.cpp:202] BatchNorm2d_1_Scale does not need backward computation.
I0328 21:35:30.897923 15789 net.cpp:202] BatchNorm2d_1_BN does not need backward computation.
I0328 21:35:30.897930 15789 net.cpp:202] Conv2d_0 does not need backward computation.
I0328 21:35:30.897936 15789 net.cpp:202] data does not need backward computation.
I0328 21:35:30.897945 15789 net.cpp:244] This network produces output BboxHead_Concat
I0328 21:35:30.897953 15789 net.cpp:244] This network produces output ClassHead_Softmax
I0328 21:35:30.897960 15789 net.cpp:244] This network produces output LandmarkHead_Concat
I0328 21:35:30.898085 15789 net.cpp:257] Network initialization done.
Finished loading model!
net forward time: 1.0882
[650, 101, 704, 169, 0, 667, 127, 691, 128, 679, 141, 668, 151, 688, 151]
[661, 503, 714, 569, 0, 675, 528, 700, 526, 689, 538, 679, 551, 699, 549]
[596, 214, 655, 295, 0, 612, 244, 639, 242, 626, 255, 616, 273, 638, 271]
[143, 323, 202, 395, 0, 163, 345, 190, 344, 179, 361, 165, 375, 187, 375]
[520, 347, 576, 412, 0, 537, 366, 563, 367, 551, 379, 537, 392, 559, 393]
[100, 449, 148, 510, 0, 114, 471, 136, 470, 127, 484, 118, 494, 135, 494]
[575, 543, 634, 610, 0, 602, 562, 625, 565, 618, 577, 603, 590, 620, 593]
[697, 390, 747, 456, 0, 709, 412, 733, 410, 721, 420, 711, 436, 731, 434]
[760, 247, 812, 305, 0, 769, 269, 793, 269, 778, 284, 773, 291, 791, 291]
[110, 249, 167, 320, 0, 126, 272, 153, 272, 140, 284, 129, 301, 150, 300]
[375, 90, 428, 150, 0, 388, 113, 412, 110, 403, 122, 395, 136, 413, 133]
[227, 10, 276, 65, 0, 241, 27, 263, 26, 254, 37, 245, 49, 263, 48]
[835, 147, 890, 224, 0, 850, 175, 875, 175, 862, 190, 853, 204, 872, 204]
[741, 3, 789, 51, 0, 749, 18, 770, 15, 759, 27, 755, 38, 772, 36]
[303, 386, 367, 465, 0, 324, 414, 352, 416, 338, 430, 325, 444, 345, 446]
[74, 44, 116, 91, 0, 85, 57, 105, 58, 95, 66, 87, 76, 103, 77]
[379, 218, 447, 287, 0, 399, 238, 426, 238, 412, 248, 401, 264, 422, 265]
[421, 1, 461, 44, 0, 436, 10, 454, 8, 449, 16, 440, 29, 455, 28]
[127, 94, 165, 146, 0, 138, 115, 155, 116, 146, 126, 137, 134, 151, 135]
[923, 219, 980, 293, 0, 950, 239, 967, 244, 959, 256, 946, 270, 958, 275]
[793, 116, 837, 173, 0, 809, 133, 828, 135, 820, 144, 807, 156, 823, 157]
[294, 107, 334, 161, 0, 303, 128, 318, 127, 308, 137, 304, 148, 316, 147]
[60, 163, 112, 224, 0, 75, 181, 99, 180, 90, 188, 79, 204, 98, 203]
[951, 58, 979, 95, 0, 956, 71, 962, 72, 955, 80, 959, 87, 963, 87]
[990, -2, 1028, 39, 0, 1006, 3, 1025, 3, 1020, 14, 1008, 25, 1023, 25]
[800, 51, 840, 101, 0, 806, 68, 818, 68, 807, 78, 809, 88, 818, 88]

test

Below is origin result:

Loading pretrained model from ./weights/mobilenet0.25_Final.pth
remove prefix 'module.'
Missing keys:0
Unused checkpoint keys:0
Used keys:300
Finished loading model!
classifications: torch.Size([1, 26240, 2])
net forward time: 0.2385
[650, 101, 704, 169, 0, 667, 127, 691, 128, 679, 141, 668, 151, 688, 151]
[661, 503, 714, 569, 0, 675, 528, 700, 526, 689, 538, 679, 551, 699, 549]
[596, 214, 655, 295, 0, 612, 244, 639, 242, 626, 255, 616, 273, 638, 271]
[143, 323, 202, 395, 0, 163, 345, 190, 344, 179, 361, 165, 375, 187, 375]
[520, 347, 576, 412, 0, 537, 366, 563, 367, 551, 379, 537, 392, 559, 393]
[100, 449, 148, 510, 0, 114, 471, 136, 470, 127, 484, 118, 494, 135, 494]
[575, 543, 634, 610, 0, 602, 562, 625, 565, 618, 577, 603, 590, 620, 593]
[697, 390, 747, 456, 0, 709, 412, 733, 410, 721, 420, 711, 436, 731, 434]
[760, 247, 812, 305, 0, 769, 269, 793, 269, 778, 284, 773, 291, 791, 291]
[110, 249, 167, 320, 0, 126, 272, 153, 272, 140, 284, 129, 301, 150, 300]
[375, 90, 428, 150, 0, 388, 113, 412, 110, 403, 122, 395, 136, 413, 133]
[227, 10, 276, 65, 0, 241, 27, 263, 26, 254, 37, 245, 49, 263, 48]
[835, 147, 890, 224, 0, 850, 175, 875, 175, 862, 190, 853, 204, 872, 204]
[741, 3, 789, 51, 0, 749, 18, 770, 15, 759, 27, 755, 38, 772, 36]
[303, 386, 367, 465, 0, 324, 414, 352, 416, 338, 430, 325, 444, 345, 446]
[74, 44, 116, 91, 0, 85, 57, 105, 58, 95, 66, 87, 76, 103, 77]
[379, 218, 447, 287, 0, 399, 238, 426, 238, 412, 248, 401, 264, 422, 265]
[421, 1, 461, 44, 0, 436, 10, 454, 8, 449, 16, 440, 29, 455, 28]
[127, 94, 165, 146, 0, 138, 115, 155, 116, 146, 126, 137, 134, 151, 135]
[923, 219, 980, 293, 0, 950, 239, 967, 244, 959, 256, 946, 270, 958, 275]
[793, 116, 837, 173, 0, 809, 133, 828, 135, 820, 144, 807, 156, 823, 157]
[294, 107, 334, 161, 0, 303, 128, 318, 127, 308, 137, 304, 148, 316, 147]
[60, 163, 112, 224, 0, 75, 181, 99, 180, 90, 188, 79, 204, 98, 203]
[951, 58, 979, 95, 0, 956, 71, 962, 72, 955, 80, 959, 87, 963, 87]
[990, -2, 1028, 39, 0, 1006, 3, 1025, 3, 1020, 14, 1008, 25, 1023, 25]
[800, 51, 840, 101, 0, 806, 68, 818, 68, 807, 78, 809, 88, 818, 88]

test

RetinaFace in PyTorch

A PyTorch implementation of RetinaFace: Single-stage Dense Face Localisation in the Wild. Model size only 1.7M, when Retinaface use mobilenet0.25 as backbone net. We also provide resnet50 as backbone net to get better result. The official code in Mxnet can be found here.

Mobile or Edge device deploy

We also provide a set of Face Detector for edge device in here from python training to C++ inference.

WiderFace Val Performance in single scale When using Resnet50 as backbone net.

Style easy medium hard
Pytorch (same parameter with Mxnet) 94.82 % 93.84% 89.60%
Pytorch (original image scale) 95.48% 94.04% 84.43%
Mxnet 94.86% 93.87% 88.33%
Mxnet(original image scale) 94.97% 93.89% 82.27%

WiderFace Val Performance in single scale When using Mobilenet0.25 as backbone net.

Style easy medium hard
Pytorch (same parameter with Mxnet) 88.67% 87.09% 80.99%
Pytorch (original image scale) 90.70% 88.16% 73.82%
Mxnet 88.72% 86.97% 79.19%
Mxnet(original image scale) 89.58% 87.11% 69.12%

FDDB Performance.

FDDB(pytorch) performance
Mobilenet0.25 98.64%
Resnet50 99.22%

Contents

Installation

Clone and install
  1. git clone https://github.com/biubug6/Pytorch_Retinaface.git

  2. Pytorch version 1.1.0+ and torchvision 0.3.0+ are needed.

  3. Codes are based on Python 3

Data
  1. Download the WIDERFACE dataset.

  2. Download annotations (face bounding boxes & five facial landmarks) from baidu cloud or dropbox

  3. Organise the dataset directory as follows:

  ./data/widerface/
    train/
      images/
      label.txt
    val/
      images/
      wider_val.txt

ps: wider_val.txt only include val file names but not label information.

Data1

We also provide the organized dataset we used as in the above directory structure.

Link: from google cloud or baidu cloud Password: ruck

Training

We provide restnet50 and mobilenet0.25 as backbone network to train model. We trained Mobilenet0.25 on imagenet dataset and get 46.58% in top 1. If you do not wish to train the model, we also provide trained model. Pretrain model and trained model are put in google cloud and baidu cloud Password: fstq . The model could be put as follows:

  ./weights/
      mobilenet0.25_Final.pth
      mobilenetV1X0.25_pretrain.tar
      Resnet50_Final.pth
  1. Before training, you can check network configuration (e.g. batch_size, min_sizes and steps etc..) in data/config.py and train.py.

  2. Train the model using WIDER FACE:

CUDA_VISIBLE_DEVICES=0,1,2,3 python train.py --network resnet50 or
CUDA_VISIBLE_DEVICES=0 python train.py --network mobile0.25

Evaluation

Evaluation widerface val

  1. Generate txt file
python test_widerface.py --trained_model weight_file --network mobile0.25 or resnet50
  1. Evaluate txt results. Demo come from Here
cd ./widerface_evaluate
python setup.py build_ext --inplace
python evaluation.py
  1. You can also use widerface official Matlab evaluate demo in Here

Evaluation FDDB

  1. Download the images FDDB to:
./data/FDDB/images/
  1. Evaluate the trained model using:
python test_fddb.py --trained_model weight_file --network mobile0.25 or resnet50
  1. Download eval_tool to evaluate the performance.

References

@inproceedings{deng2019retinaface,
title={RetinaFace: Single-stage Dense Face Localisation in the Wild},
author={Deng, Jiankang and Guo, Jia and Yuxiang, Zhou and Jinke Yu and Irene Kotsia and Zafeiriou, Stefanos},
booktitle={arxiv},
year={2019}

About

convert mobilenet0.25_Final.pth to caffemodel in [Pytorch_Retinaface](https://github.com/biubug6/Pytorch_Retinaface)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages