Skip to main content

Deep Face Anaylsis Framework for Face Recognition and Demography

Project description

deepface

Downloads

Deepface is a lightweight facial analysis framework including face recognition and demography (age, gender, emotion and race) for Python. Modern face recognition pipelines consist of 4 stages: detect, align, represent and verify. Deepface handles all these common stages in the background. You can use the framework with a just few lines of codes

Face Recognition

Verify function under the DeepFace interface is used for face recognition.

from deepface import DeepFace
result = DeepFace.verify("img1.jpg", "img2.jpg")

{
   "verified": true,
   "distance": 0.25638097524642944,
   "max_threshold_to_verify": 0.40,
   "model": "VGG-Face",
   "similarity_metric": "cosine"
}

You can retrieve the fields of the response object easily in Python.

print("Is verified: ", result["verified"])
print("Distance: ", result["distance"])

Each call of verification function builds a face recognition model scratch and this is a costly operation. If you are going to verify multiple faces sequentially, then you should pass an array to verify function to speed the operation up. In this way, complex face recognition models will be built once.

dataset = [
	['dataset/img1.jpg', 'dataset/img2.jpg'],
	['dataset/img5.jpg', 'dataset/img6.jpg']
]
result = DeepFace.verify(dataset)

Face recognition models

Face recognition can be handled by different models. Currently, VGG-Face , Google Facenet, OpenFace and Facebook DeepFace models are supported in deepface. The default configuration verifies faces with VGG-Face model. You can set the base model while verification as illustared below. Accuracy and speed show difference based on the performing model.

vggface_result = DeepFace.verify("img1.jpg", "img2.jpg") #default is VGG-Face
#vggface_result = DeepFace.verify("img1.jpg", "img2.jpg", model_name = "VGG-Face") #identical to the line above
facenet_result = DeepFace.verify("img1.jpg", "img2.jpg", model_name = "Facenet")
openface_result = DeepFace.verify("img1.jpg", "img2.jpg", model_name = "OpenFace")
deepface_result = DeepFace.verify("img1.jpg", "img2.jpg", model_name = "DeepFace")

VGG-Face has the highest accuracy score but it is not convenient for real time studies because of its complex structure. FaceNet is a complex model as well. On the other hand, OpenFace has a close accuracy score but it performs the fastest. That's why, OpenFace is much more convenient for real time studies.

Similarity

These models actually find the vector embeddings of faces. Decision of verification is based on the distance between vectors. Distance could be found by different metrics such as Cosine Similarity, Euclidean Distance and L2 form. The default configuration finds the cosine similarity. You can alternatively set the similarity metric while verification as demostratred below.

result = DeepFace.verify("img1.jpg", "img2.jpg", model_name = "VGG-Face", distance_metric = "cosine")
result = DeepFace.verify("img1.jpg", "img2.jpg", model_name = "VGG-Face", distance_metric = "euclidean")
result = DeepFace.verify("img1.jpg", "img2.jpg", model_name = "VGG-Face", distance_metric = "euclidean_l2")

Facial Attribute Analysis

Deepface also offers facial attribute analysis including age, gender, emotion and race predictions. Analysis function under the DeepFace interface is used to find demography of a face.

from deepface import DeepFace
demography = DeepFace.analyze("img4.jpg") #passing nothing as 2nd argument will find everything
#demography = DeepFace.analyze("img4.jpg", ['age', 'gender', 'race', 'emotion']) #identical to the line above

demographies = DeepFace.analyze(["img1.jpg", "img2.jpg", "img3.jpg"]) #analyzing multiple faces same time

Analysis function returns a json object.

{
"age": 32.49221594557578,
"gender": "Woman",
"race": {
   "asian": 3.928472101688385, 
   "white": 55.44567108154297, 
   "middle eastern": 15.896821022033691, 
   "indian": 3.050043433904648, 
   "latino hispanic": 20.90577930212021, 
   "black": 0.7732132915407419
},
"dominant_race": "white",
"emotion": {
   "angry": 3.1055836006999016, 
   "fear": 1.1844050139188766, 
   "neutral": 86.2661361694336, 
   "sad": 7.137920707464218, 
   "disgust": 0.0001227657776325941, 
   "happy": 2.245445176959038, 
   "surprise": 0.06038688006810844
}, 
"dominant_emotion": "neutral"
}

Then, you can retrieve the fields of the response object easily in Python.

print("Age: ", demography["age"])
print("Gender: ", demography["gender"])
print("Emotion: ", demography["dominant_emotion"])

Installation

The easiest way to install deepface is to download it from PyPI.

pip install deepface

Alternatively, you can directly download the source code from this repository. GitHub repo might be newer than the PyPI version.

git clone https://github.com/serengil/deepface.git
cd deepface
pip install -e .

Initial tests are run for Python 3.5.5 on Windows 10 but this is an OS-independent framework. Even though pip handles to install dependent libraries, the framework basically needs the following dependencies. You might need the following library requirements if you install the source code from github.

pip install numpy==1.14.0
pip install pandas==0.23.4
pip install matplotlib==2.2.2
pip install gdown==3.10.1
pip install opencv-python==3.4.4
pip install tensorflow==1.9.0
pip install keras==2.2.0
pip install tqdm==4.30.0
pip install Pillow==5.2.0

Playlist

Deepface is mentioned in this youtube playlist.

Disclaimer

Reference face recognition models have different type of licenses. This framework is just a wrapper for those models. That's why, licence types are inherited as well. You should check the licenses for the face recognition models before use.

Herein, OpenFace is licensed under Apache License 2.0. FB DeepFace and Facenet is licensed under MIT License. The both Apache License 2.0 and MIT license types allow you to use for commercial purpose.

On the other hand, VGG-Face is licensed under Creative Commons Attribution License. That's why, it is restricted to adopt VGG-Face for commercial use.

Support

There are many ways to support a project - starring⭐️ the GitHub repos is just one.

Licence

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

Logo is created by Adrien Coquet. Licensed under Creative Commons: By Attribution 3.0 License.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deepface-0.0.10.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

deepface-0.0.10-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file deepface-0.0.10.tar.gz.

File metadata

  • Download URL: deepface-0.0.10.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.4

File hashes

Hashes for deepface-0.0.10.tar.gz
Algorithm Hash digest
SHA256 16fd4a2f857a8b5142d044874c446e08a42f00de407585e62b5d7282c19a7880
MD5 1eb52195d503188c29e85b9933215f7e
BLAKE2b-256 100d2fd1f4e8ec9c9359ff293eb603989a6ccefe7ecb47182aff1a49431b7918

See more details on using hashes here.

File details

Details for the file deepface-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: deepface-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.4

File hashes

Hashes for deepface-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 4877b05daf75c8f11088e2e6dfd4bc2a7bb818d43ce37f7a3aa47ea7d04d023a
MD5 03e0639f23faa3e468e054f390137a43
BLAKE2b-256 62b74c960e8f2d15a97d9644b4f2b78bc77de2849a063ad4d3169a10628dacc4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page