Skip to main content

Face detection and recognition library that focuses on speed and ease of use.

Project description

dFace

Face detection and recognition library that focuses on speed and ease of use. This is a stripped down version of timesler's facenet repo with some improvements notably on memory overflows. This repository is actively developed and used in production.

MTCNN is used for face detection and FaceNet is used for generating face embeddings.

Installation

Both algorithms can be used directly by copying the source file into your code base. They are single file and single model implementations with no interdependence.

Alternatively you can install with pip3 install dface command. Weights will be downloaded from github automatically in the first run.

MTCNN

This implementation takes a list of frames and returns a list of detected faces. The input and output lists always have the same size. If no face is detected for a frame, the corresponding list element is returned None, otherwise it's a tuple of three elements; (bounding_boxes, probabilities, landmarks).

mtcnn = MTCNN('cuda')
...
result = mtcnn.detect(frames)
for res in result:
    if res is None:
        continue
    boxes, probs, lands = res

Bounding boxes is a list of four coordinates (x1, y1, x2, y2) for each face detected in the frame. Probabilities is a list of confidence scores between 0 and 1 for each face. Landmarks is a list of facial landmark points. There are five points for each face.

The implementation is at mtcnn.py

FaceNet

This implementation takes a list of cropped faces and returns a list of face embedding vector of 512 dimensions. These embeddings then can be used for detecting facial similarities, clustering identities and so on.

facenet = FaceNet('cuda')
...
embeds = facenet.embedding(faces)

The implementation is at facenet.py

Both algorithms accept model path as the second argument if you want to load models from a custom location.

Full working example

The repo contains an example script that uses both MTCNN and Facenet to read a video and cluster the faces. It uses OpenCV to read video frames and DBSCAN to cluster faces.

You can run the example by simply typing: python3 example.py video.mp4. A directory will be created with the same name as video that contains clustered identities. The following is an example image.

the dude

The implementation is at example.py

Project details


Download files

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

Source Distribution

dface-1.1.4.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

dface-1.1.4-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file dface-1.1.4.tar.gz.

File metadata

  • Download URL: dface-1.1.4.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for dface-1.1.4.tar.gz
Algorithm Hash digest
SHA256 3897d0515b2b0db64e459e643c17ec85301fe0c8c6e4d3cf1b31cbc0a594e505
MD5 cd09dd69f53736cf6caab357a8cff56e
BLAKE2b-256 6ef6e78e5eb7b4339418d3e57efb5699dcbd6da488488d23ad0f003e99024684

See more details on using hashes here.

Provenance

File details

Details for the file dface-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: dface-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for dface-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 611b29eb191c9b8f4909cccb043f5d9962f5d2270ca62859e1c59f0ccca13fb8
MD5 fcc5a981ea4d14a3e0c1a81ef6577d28
BLAKE2b-256 ce0a39da5306f199f16bac735209141d54460ec44fa9d4e7fd84e3e97bdecead

See more details on using hashes here.

Provenance

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