tiny-face-pytorch

๐Ÿ“ธ Tiny-Face: Ultra-lightweight Face Detection

Downloads GitHub Repo stars GitHub Repository GitHub License

Tiny-Face is an ultra-lightweight face detection model optimized for mobile and edge devices. Built upon the concepts of RetinaFace, this model achieves high precision and speed in face detection with minimal resource requirements.

Note
This repository refines lightweight architectures like RetinaFace (mobile), Slim and RFB with a focus on Tiny-level efficiency.

๐Ÿ“ˆ Performance on WiderFace

Multi-scale Image Size

Models Pretrained on ImageNet Easy Medium Hard #Params(M) Size(MB)
SlimFace False 79.50% 79.40% 68.36% 0.343 1.4
RFB False 80.49% 81.51% 75.73% 0.359 1.5
RetinaFace True 87.69% 86.39% 80.21% 0.426 1.8

Original Image Size

Models Pretrained on ImageNet Easy Medium Hard #Params(M)
SlimFace False 87.10% 84.36% 67.38% 0.343
RFB False 87.09% 84.61% 69.22% 0.359
RetinaFace True 90.26% 87.48% 72.85% 0.426

โœจ Features

Download model weights

All weights are available in GitHub release v0.0.1.

Models PyTorch Weights ONNX Weights Input Size
SlimFace slimface.pth slimface.onnx 640x640
RFB rfb.pth rfb.onnx 640x640
RetinaFace retinaface.pth retinaface.onnx 640x640

โš™๏ธ Installation

  1. Clone the repository:

    git clone https://github.com/yakhyo/tiny-face-pytorch.git
    cd tiny-face-pytorch
    
  2. Install dependencies:

    pip install -r requirements.txt
    

๐Ÿ“‚ Dataset Setup

  1. Download the Dataset:

    • Download the WIDERFACE dataset.
    • Download annotations (face bounding boxes & five facial landmarks) from Baidu Cloud (password: fstq) or Dropbox.
  2. Organize the Dataset Directory:

    Structure your dataset directory as follows:

    data/
    โ””โ”€โ”€ widerface/
       โ”œโ”€โ”€ train/
       โ”‚   โ”œโ”€โ”€ images/
       โ”‚   โ””โ”€โ”€ label.txt
       โ””โ”€โ”€ val/
          โ”œโ”€โ”€ images/
          โ””โ”€โ”€ wider_val.txt
    

[!NOTE]
wider_val.txt only includes val file names but not label information.

There is also an organized dataset (as shown above): Link from Google Drive or Baidu Cloud (password: ruck). Thanks to biubug6 for the organized dataset.

๐Ÿ‹๏ธโ€โ™‚๏ธ Training

To train a model, specify the network backbone:

python train.py --network slim  # Replace 'slim' with your choice of model

Available Models:

๐Ÿ“Š Inference

Inference the model using:

python detect.py --network retinaface --weights weights/retinaface.pth
                           slim                 weights/slim.pth
                           rfb                  weights/rfb.pth

Model found following number of faces from large selfi image:

RetinaFace model inference result.

๐Ÿงช Evaluating RetinaFace on WiderFace Dataset

1. Get and Install WiderFace Evaluation Tool

  1. Clone the WiderFace evaluation repository inside the tiny-face-pytorch folder:
    git clone https://github.com/yakhyo/widerface_evaluation
    
  2. Navigate to the widerface_evaluation folder and build the required extension:
    cd widerface_evaluation
    python3 setup.py build_ext --inplace
    
  3. Return to the tiny-face-pytorch folder after installation is complete:
    cd ..
    

2. Generate Predictions

Run the following command to evaluate your model with WiderFace, specifying the model architecture (mobilenetv1_0.25 in this example) and the path to the trained weights. Predictions will be stored in widerface_txt inside the widerface_evaluation folder.

python evaluate_widerface.py --network retinaface --weights weights/retinaface.pth
                                       slim                 weights/slim.pth
                                       rfb                  weights/rfb.pth

3. Run the Final Evaluation

After generating predictions, navigate to the widerface_evaluation folder and run the following command to compare predictions with the ground truth annotations:

cd widerface_evaluation
python evaluation.py -p widerface_txt -g ground_truth

[!NOTE]
Ensure ground_truth is the path to the WiderFace ground truth directory.

This will begin the evaluation process of your model on the WiderFace dataset.

๐Ÿ“œ License

This project is licensed under the MIT License. See the LICENSE file for details.

๐Ÿ”— References