Skip to main content

Multi-task Cascaded Convolutional Neural Networks for Face Detection, based on TensorFlow

Project description

MTCNN

https://badge.fury.io/py/mtcnn.svg https://travis-ci.org/ipazc/mtcnn.svg?branch=master

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

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

INSTALLATION

Currently it is only supported Python3.4 onwards. It can be installed through pip:

$ pip install mtcnn

This implementation requires OpenCV>=4.1 and Keras>=2.0.0 (any Tensorflow supported by Keras will be supported by this MTCNN package). If this is the first time you use tensorflow, you will probably need to install it in your system:

$ pip install tensorflow

or with conda

$ conda install tensorflow

Note that tensorflow-gpu version can be used instead if a GPU device is available on the system, which will speedup the results.

USAGE

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

>>> from mtcnn import MTCNN
>>> import cv2
>>>
>>> img = cv2.cvtColor(cv2.imread("ivan.jpg"), cv2.COLOR_BGR2RGB)
>>> detector = MTCNN()
>>> 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).

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

BENCHMARK

The following tables shows the benchmark of this mtcnn implementation running on an Intel i7-3612QM CPU @ 2.10GHz, with a CPU-based Tensorflow 1.4.1.

  • Pictures containing a single frontal face:

Image size

Total pixels

Process time

FPS

460x259

119,140

0.118 seconds

8.5

561x561

314,721

0.227 seconds

4.5

667x1000

667,000

0.456 seconds

2.2

1920x1200

2,304,000

1.093 seconds

0.9

4799x3599

17,271,601

8.798 seconds

0.1

  • Pictures containing 10 frontal faces:

Image size

Total pixels

Process time

FPS

474x224

106,176

0.185 seconds

5.4

736x348

256,128

0.290 seconds

3.4

2100x994

2,087,400

1.286 seconds

0.7

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.

For more reference about the network definition, take a close look at the paper from Zhang et al. (2016) [ZHANG2016].

LICENSE

MIT License.

REFERENCE

[ZHANG2016] (1,2)

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.

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

mtcnn-0.1.0.tar.gz (2.3 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mtcnn-0.1.0-py3.7.egg (2.3 MB view details)

Uploaded Egg

mtcnn-0.1.0-py3-none-any.whl (2.3 MB view details)

Uploaded Python 3

File details

Details for the file mtcnn-0.1.0.tar.gz.

File metadata

  • Download URL: mtcnn-0.1.0.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.3

File hashes

Hashes for mtcnn-0.1.0.tar.gz
Algorithm Hash digest
SHA256 56624f08e088e5cf062de8005df09696cdbc0f4c2fc3578483b19e0fb3984252
MD5 8a10e0e5896e8a92485863ddcc47186a
BLAKE2b-256 b48e6565beb364587befbef5efad314e14f78be85d65c3709a4da09bd9dfbb65

See more details on using hashes here.

File details

Details for the file mtcnn-0.1.0-py3.7.egg.

File metadata

  • Download URL: mtcnn-0.1.0-py3.7.egg
  • Upload date:
  • Size: 2.3 MB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.3

File hashes

Hashes for mtcnn-0.1.0-py3.7.egg
Algorithm Hash digest
SHA256 d991b5bf3c4fa61b9e28b1a9a0005e0a57adc8d7aaa49833ed1010bb8d5aa670
MD5 8074cb2ac2c48deba5f0f2f3f40fe2d2
BLAKE2b-256 b6bc0bed76312f52ef2914d6ff88cce67a27f257b1d3729a614be4c33d5a30e2

See more details on using hashes here.

File details

Details for the file mtcnn-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mtcnn-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.3

File hashes

Hashes for mtcnn-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5168c3a5ab9bb91e97a370134982f07daf745ac003db51b92fe4c666331ef10c
MD5 b5118839699dd2254a082bf3f43de13a
BLAKE2b-256 6743abee91792797c609c1bf30f1112117f7a87a713ebaa6ec5201d5555a73ef

See more details on using hashes here.

Supported by

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