Skip to main content

MTCNN

https://badge.fury.io/py/mtcnn.svg

Implementation of the MTCNN face detector for TensorFlow. It is written from scratch, using as a reference the implementation of MTCNN from David Sandberg (FaceNet’s MTCNN). It is based on the paper Zhang et al. (2016) [ZHANG2016].

https://github.com/ipazc/mtcnn/raw/master/result.jpg

INSTALLATION

Currently it is only supported python3 onwards. It can be installed with pip:

$ pip3 install mtcnn

USAGE

The following example illustrates the ease of use of this package:

>>> from mtcnn.mtcnn import MTCNN
>>> import cv2
>>>
>>> img = cv2.imread("ivan.jpg")
>>> detector = MTCNN()
>>> print(detector.detect_faces(img))
[{'box': [277, 90, 48, 63], 'keypoints': {'nose': (303, 131), 'mouth_right': (313, 141), 'right_eye': (314, 114), 'left_eye': (291, 117), 'mouth_left': (296, 143)}, 'confidence': 0.99851983785629272}]

The detector returns a list of JSON objects. Each JSON object contains three main keys: ‘box’, ‘confidence’ and ‘keypoints’:

  • The bounding box is formatted as [x, y, width, height] under the key ‘box’.

  • The confidence is the probability for a bounding box to be matching a face.

  • The keypoints are formatted into a JSON object with the keys ‘left_eye’, ‘right_eye’, ‘nose’, ‘mouth_left’, ‘mouth_right’. Each keypoint is identified by a pixel position (x, y).

A good example of usage can be found in the file “example.py.” located in the root of this repository.

MODEL

By default the MTCNN bundles a face detection weights model.

The model is adapted from the Facenet’s MTCNN implementation, merged in a single file located inside the folder ‘data’ relative to the module’s path. It can be overriden by injecting it into the MTCNN() constructor during instantiation.

The model must be numpy-based containing the 3 main keys “pnet”, “rnet” and “onet”, having each of them the weights of each of the layers of the network.

REFERENCE

[ZHANG2016]

Zhang, K., Zhang, Z., Li, Z., and Qiao, Y. (2016). Joint face detection and alignment using multitask cascaded convolutional networks. IEEE Signal Processing Letters, 23(10):1499–1503.

Release files for mtcnn 0.0.2

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

Source distribution (sdist)

Source distribution for mtcnn 0.0.2
File Size Uploaded
mtcnn-0.0.2.tar.gz 2.3 MB Details

Release files / mtcnn-0.0.2.tar.gz

Download URL mtcnn-0.0.2.tar.gz
Size 2.3 MB
Tags Source
SHA-256 checksum
How to use checksums
a354fa70003ab02128922d6b66cf7a46c624afef3cc727767c047f3fdf7ac47f
BLAKE2b-256 checksum
How to use checksums
42b22277daba60f5ce099d9f7cb9f7f5353508646ad9e48d34e7a814d496496b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.0.0

2 release files

0.1.1

2 release files

0.1.0

3 release files

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

This release

0.0.2 This release

1 release file

0.0.1

1 release file

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