Sign inSign up

serengil/deepface

By serengil

•Updated 10 months ago

Dockerized DeepFace: A Containerized Face Recognition and Facial Attribute Analysis Service

Image
Machine learning & AI
Data science
9

100K+

serengil/deepface repository overview

⁠Dockerized DeepFace: A Containerized Face Recognition and Facial Attribute Analysis Service

Downloads Stars Pulls License Tests DOI

Blog YouTube Twitter

Patreon GitHub Sponsors Buy Me a Coffee

Repo: https://github.com/serengil/deepface⁠

Video Tutorial: https://youtu.be/9Tk9lRQareA⁠

⁠Running The Service

Firstly, pull the latest deepface image

docker pull serengil/deepface

Secondly, run the deepface via docker

docker run -p 5005:5000 deepface

This will get the deepface service up at http://localhost:5005⁠. Confirm it is accessible from the browser.

Now, you are able to call deepface functionalities.

This postman collection⁠ will guide you how to call deepface functionalities.

⁠Face Verification

You can call the face verification method at the endpoint http://localhost:5005/verify using an HTTP POST request with the following body:

  {
    "img1_path": "https://raw.githubusercontent.com/serengil/deepface/master/tests/dataset/img1.jpg",
    "img2_path": "https://raw.githubusercontent.com/serengil/deepface/master/tests/dataset/img2.jpg"
  },
    "model_name": "VGG-Face",
    "detector_backend": "opencv",
    "distance_metric": "cosine"

The response will look like this:

{
    "detector_backend": "opencv",
    "distance": 0.42272907319751785,
    "facial_areas": {
        "img1": {
            "h": 768,
            "left_eye": [
                850,
                524
            ],
            "right_eye": [
                571,
                517
            ],
            "w": 768,
            "x": 339,
            "y": 218
        },
        "img2": {
            "h": 491,
            "left_eye": [
                858,
                388
            ],
            "right_eye": [
                663,
                390
            ],
            "w": 491,
            "x": 524,
            "y": 201
        }
    },
    "model": "VGG-Face",
    "similarity_metric": "cosine",
    "threshold": 0.68,
    "time": 3.39,
    "verified": true
}

Check the verified key in the response payload for verification status.

You can also send base64 encoded strings instead of URLs.

⁠Facial Attribute Analysis

This method allows you to predict age, gender, emotion, and race/ethnicity. The endpoint address is http://127.0.0.1:5005/analyze. Use an HTTP POST request with the following body:

{
    "img_path": "https://raw.githubusercontent.com/serengil/deepface/master/tests/dataset/img1.jpg",
    "actions": ["age", "gender", "emotion", "race"]
}

The response will provide predictions on apparent age, gender, emotion, and ethnicity:

{
    "results": [
        {
            "age": 31,
            "dominant_emotion": "sad",
            "dominant_gender": "Man",
            "dominant_race": "white",
            "emotion": {
                "angry": 10.380517944035775,
                "disgust": 0.34448695919073113,
                "fear": 41.99173247912735,
                "happy": 0.031012031045239443,
                "neutral": 2.4377143829805394,
                "sad": 44.47406298231328,
                "surprise": 0.34046527596231985
            },
            "face_confidence": 0.89,
            "gender": {
                "Man": 99.99207258224487,
                "Woman": 0.007924179953988642
            },
            "race": {
                "asian": 1.6582146286964417,
                "black": 0.2634486649185419,
                "indian": 1.1727581731975079,
                "latino hispanic": 41.77250564098358,
                "middle eastern": 10.031893849372864,
                "white": 45.10117769241333
            },
            "region": {
                "h": 681,
                "left_eye": null,
                "right_eye": null,
                "w": 681,
                "x": 1436,
                "y": 336
            }
        },
        {
            "age": 31,
            "dominant_emotion": "neutral",
            "dominant_gender": "Woman",
            "dominant_race": "white",
            "emotion": {
                "angry": 0.05392062594182789,
                "disgust": 0.00015850500858505256,
                "fear": 0.35890184808522463,
                "happy": 43.93383264541626,
                "neutral": 54.20163869857788,
                "sad": 1.254333183169365,
                "surprise": 0.19721481949090958
            },
            "face_confidence": 0.92,
            "gender": {
                "Man": 0.021838860993739218,
                "Woman": 99.97816681861877
            },
            "race": {
                "asian": 0.25855733547359705,
                "black": 0.016115940525196493,
                "indian": 0.2287688199430704,
                "latino hispanic": 5.218064412474632,
                "middle eastern": 8.171910792589188,
                "white": 86.10658645629883
            },
            "region": {
                "h": 758,
                "left_eye": [
                    833,
                    819
                ],
                "right_eye": [
                    553,
                    860
                ],
                "w": 758,
                "x": 326,
                "y": 542
            }
        }
    ]
}

Like face verification, this method also supports base64 encoded strings instead of URLs.

⁠Represent

This method generates vector embeddings for given images. The endpoint address is http://127.0.0.1:5005/represent. Use an HTTP POST request with the following body:

{
  "model_name": "VGG-Face",
  "detector_backend": "opencv",
  "img": "https://raw.githubusercontent.com/serengil/deepface/master/tests/dataset/img1.jpg"
}

The response will include the vector embeddings:

{
    "results": [
        {
            "embedding": [
                0.013881363057331663,
                0.0865466348140943,
                0.00843181578293164,
                0.08922029773772754,
                0.009442750920063645,
                0.0585725425777175,
                0.010859464741657977,
                # ...
            ],
            "face_confidence": 0.92,
            "facial_area": {
                "h": 768,
                "left_eye": [
                    850,
                    524
                ],
                "right_eye": [
                    571,
                    517
                ],
                "w": 768,
                "x": 339,
                "y": 218
            }
        }
    ]
}

⁠Citation

If you use deepface in your research, please cite this publication:

@article{serengil2026boosted,
  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}
}

Tag summary

Content type

Image

Digest

sha256:58d96a2ff…

Size

1.7 GB

Last updated

10 months ago

docker pull serengil/deepface