Skip to content

yakhyo/tiny-face-pytorch

Repository files navigation

πŸ“Έ Tiny-Face: Ultra-lightweight Face Detection

Downloads GitHub Repo stars GitHub Repository GitHub License

out_retina.mp4

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

  • Tiny-sized Efficiency: Ultra-lightweight and optimized for low-resource devices.
  • Mobile-friendly: Includes Slim, RFB, and MobileNetV1_0.25 configurations.
  • Pretrained Backbones: Models suitable for mobile and embedded systems.

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:

  • retinaface
  • slim
  • rfb

πŸ“Š 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: 459
  • RFB: 430
  • Slim: 384

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

About

πŸš€ | Ultra-lightweight 1MB face detection & landmarks models for mobile and edge devices. > ONNX > WebCam

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages