Skip to main content

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

Metadata

Release files for dface 1.1.5

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

Source distribution (sdist)

Source distribution for dface 1.1.5
File Size Uploaded
dface-1.1.5.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dface 1.1.5
File Interpreter ABI Platform
dface-1.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 kB

Release files / dface-1.1.5.tar.gz

Download URL dface-1.1.5.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
51034525b3720070f9014ac8ba6cea8f6c5f3ec642638077c4fa51020e9977f2
BLAKE2b-256 checksum
How to use checksums
defbd7251e350b80f01797caaf9896c9fafb7d562e20b997044ea5d021ddd476
Upload date
Uploaded using Trusted Publishing?
What is 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.5

Release files / dface-1.1.5-py3-none-any.whl

Download URL dface-1.1.5-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b8bce15e1b4c952d92db44c04273e2dec9503eb313920e631eb6037dcdd7f5ea
BLAKE2b-256 checksum
How to use checksums
b8519c557320ff18ecc240fa13e79f25b35e89bce25e91e9afd3388ddd4eb586
Upload date
Uploaded using Trusted Publishing?
What is 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.5

Release history Release notifications | RSS feed

This release

1.1.5 This release

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1

2 release files

1.0

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