Skip to main content

RetinaFace

PyPI Downloads Stars License DOI

RetinaFace is a deep learning based cutting-edge facial detector for Python coming with facial landmarks. Its detection performance is amazing even in the crowd as shown in the following illustration.

RetinaFace is the face detection module of insightface project. The original implementation is mainly based on mxnet. Then, its tensorflow based re-implementation is published by Stanislas Bertrand. So, this repo is heavily inspired from the study of Stanislas Bertrand. Its source code is simplified and it is transformed to pip compatible but the main structure of the reference model and its pre-trained weights are same.


The Yellow Angels - Fenerbahce Women's Volleyball Team

Installation PyPI

The easiest way to install retinaface is to download it from PyPI. RetinaFace runs on TensorFlow, PyTorch or ONNX Runtime. ONNX Runtime comes with the base installation, so retinaface works out of the box.

# to run retinaface on top of onnx runtime
$ pip install retina-face

# or to run retinaface on top of tensorflow
# $ pip install retina-face[tensorflow]

# or to run retinaface on top of pytorch
# $ pip install retina-face[pytorch]

# manage the backend deep learning framework if you have many
# export DEEPFACE_BACKEND_ENGINE=onnx 

Alternatively, you can also install deepface from its source code. Source code may have new features not published in pip release yet.

$ git clone https://github.com/serengil/retinaface.git
$ cd retinaface
$ pip install -e .  # or pip install -e .[tensorflow] or .[pytorch]

Then, you will be able to import the library and use its functionalities.

from retinaface import RetinaFace

Face Detection - Demo

RetinaFace offers a face detection function. It expects an exact path of an image as input.

resp = RetinaFace.detect_faces("img1.jpg")

Then, it will return the facial area coordinates and some landmarks (eyes, nose and mouth) with a confidence score.

{
    "face_1": {
        "score": 0.9993440508842468,
        "facial_area": [155, 81, 434, 443],
        "landmarks": {
          "right_eye": [257.82974, 209.64787],
          "left_eye": [374.93427, 251.78687],
          "nose": [303.4773, 299.91144],
          "mouth_right": [228.37329, 338.73193],
          "mouth_left": [320.21982, 374.58798]
        }
  }
}

Alignment - Tutorial, Demo

A modern face recognition pipeline consists of 4 common stages: detect, align, normalize, represent and verify. Experiments show that alignment increases the face recognition accuracy almost 7%. Here, retinaface can find the facial landmarks including eye coordinates. In this way, it can apply alignment to detected faces with its extracting faces function.

import matplotlib.pyplot as plt
faces = RetinaFace.extract_faces(img_path = "img.jpg", align = True)
for face in faces:
  plt.imshow(face)
  plt.show()

Face Recognition - Demo

Notice that face recognition module of insightface project is ArcFace, and face detection module is RetinaFace. ArcFace and RetinaFace pair is wrapped in deepface library for Python. Consider to use deepface if you need an end-to-end face recognition pipeline.

#!pip install deepface
from deepface import DeepFace
obj = DeepFace.verify("img1.jpg", "img2.jpg"
          , model_name = 'ArcFace', detector_backend = 'retinaface')
print(obj["verified"])

Notice that ArcFace got 99.40% accuracy on LFW data set whereas human beings just have 97.53% confidence.

Contribution Tests

Pull requests are more than welcome! You should run the unit tests and linting locally before creating a PR. Commands make test and make lint will help you to run it locally. Once a PR created, GitHub test workflow will be run automatically and unit test results will be available in GitHub actions before approval.

Support

There are many ways to support a project. Starring⭐️ the repo is just one 🙏

You can also support this work on Patreon, GitHub Sponsors, or Buy Me a Coffee.

Also, your company's logo will be shown on README on GitHub if you become sponsor in gold, silver or bronze tiers.

Acknowledgements

This work is mainly based on the insightface project and retinaface paper; and it is heavily inspired from the re-implementation of retinaface-tf2 by Stanislas Bertrand. Finally, Bertrand's implementation uses Fast R-CNN written by Ross Girshick in the background. All of those reference studies are licensed under MIT license.

Citation

If you are using RetinaFace in your research, please consider to cite its original research paper. Besides, if you are using this re-implementation of retinaface, please consider to cite the following research paper as well. Here is example of its BibTeX entry:

@article{deepface,
  title     =  {Boosted LightFace: A Hybrid DNN and GBM Model for Boosted Facial Recognition},
  author    =  {Serengil, Sefik Ilkin and Ozpinar, Alper},
  journal   =  {Gazi University Journal of Science},
  volume    =  {39},
  number    =  {1},
  pages     =  {452-466},
  year      =  {2026},
  doi       =  {10.35378/gujs.1794891},
  url       =  {https://dergipark.org.tr/en/pub/gujs/article/1794891},
  publisher =  {Gazi University}
}

Finally, if you use this RetinaFace re-implementation in your GitHub projects, please add retina-face dependency in the requirements.txt.

Licence

This project is licensed under the MIT License - see LICENSE for more details.

Metadata

Release files for retina-face 0.0.19

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for retina-face 0.0.19
File Size Uploaded
retina_face-0.0.19.tar.gz 27.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for retina-face 0.0.19
File Interpreter ABI Platform
retina_face-0.0.19-py3-none-any.whl Python 3 none any Details

Total release size: 61.1 kB

Release files / retina_face-0.0.19.tar.gz

Download URL retina_face-0.0.19.tar.gz
Size 27.8 kB
Tags Source
SHA-256 checksum
How to use checksums
24dc048609562d7dd71b2180215e2e437f1e752514bf27b2cc3dd3af61cf3406
BLAKE2b-256 checksum
How to use checksums
75c63fcd0801518be0c16196e35b2c74f7cca35f0a0ec8902a6313831d1f44fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.31.0 requests-toolbelt/0.10.1 urllib3/1.26.15 tqdm/4.50.2 importlib-metadata/6.8.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.5

Release files / retina_face-0.0.19-py3-none-any.whl

Download URL retina_face-0.0.19-py3-none-any.whl
Size 33.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
117c528129963ee6b3c9b3b36991ef11e9f76586868d46132ff7b47e0cbd761c
BLAKE2b-256 checksum
How to use checksums
cf7c08e7f17ac32dc81f9c002a1cc2983710bdc8688718221b882c068caff117
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.31.0 requests-toolbelt/0.10.1 urllib3/1.26.15 tqdm/4.50.2 importlib-metadata/6.8.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.0.19 This release

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page