mtcnn


Namemtcnn JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttp://github.com/ipazc/mtcnn
SummaryMulti-task Cascaded Convolutional Neural Networks for Face Detection, based on TensorFlow
upload_time2021-07-09 11:16:46
maintainer
docs_urlNone
authorIván de Paz Centeno
requires_python
licenseMIT
keywords mtcnn face detection tensorflow pip package
VCS
bugtrack_url
requirements keras opencv-python
Travis-CI
coveralls test coverage No coveralls.
            MTCNN
#####

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


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 <https://github.com/davidsandberg/facenet/tree/master/src/align>`_) in Facenet. It is based on the paper *Zhang, K et al. (2016)* [ZHANG2016]_.

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


INSTALLATION
############

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

.. code:: bash

    $ 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:

.. code:: bash

    $ pip install tensorflow

or with `conda`

.. code:: bash

    $ 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:


.. code:: python

    >>> 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. Also, you can run the Jupyter Notebook "`example.ipynb`_" for another example of usage.

BENCHMARK
=========

The following tables shows the benchmark of this mtcnn implementation running on an `Intel i7-3612QM CPU @ 2.10GHz <https://www.cpubenchmark.net/cpu.php?cpu=Intel+Core+i7-3612QM+%40+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] 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.

.. _example.py: example.py
.. _example.ipynb: example.ipynb
.. _MIT license: LICENSE



            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/ipazc/mtcnn",
    "name": "mtcnn",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "mtcnn face detection tensorflow pip package",
    "author": "Iv\u00e1n de Paz Centeno",
    "author_email": "ipazc@unileon.es",
    "download_url": "https://files.pythonhosted.org/packages/ef/11/d549caa104ac2a03b6ef32bfca841ebb04c99ddf704b197c272bcdec054d/mtcnn-0.1.1.tar.gz",
    "platform": "",
    "description": "MTCNN\n#####\n\n.. image:: https://badge.fury.io/py/mtcnn.svg\n    :target: https://badge.fury.io/py/mtcnn\n.. image:: https://travis-ci.org/ipazc/mtcnn.svg?branch=master\n    :target: https://travis-ci.org/ipazc/mtcnn\n\n\nImplementation of the MTCNN face detector for Keras in Python3.4+. It is written from scratch, using as a reference the implementation of\nMTCNN from David Sandberg (`FaceNet's MTCNN <https://github.com/davidsandberg/facenet/tree/master/src/align>`_) in Facenet. It is based on the paper *Zhang, K et al. (2016)* [ZHANG2016]_.\n\n.. image:: https://github.com/ipazc/mtcnn/raw/master/result.jpg\n\n\nINSTALLATION\n############\n\nCurrently it is only supported Python3.4 onwards. It can be installed through pip:\n\n.. code:: bash\n\n    $ pip install mtcnn\n\nThis implementation requires OpenCV>=4.1 and Keras>=2.0.0 (any Tensorflow supported by Keras will be supported by this MTCNN package).\nIf this is the first time you use tensorflow, you will probably need to install it in your system:\n\n.. code:: bash\n\n    $ pip install tensorflow\n\nor with `conda`\n\n.. code:: bash\n\n    $ conda install tensorflow\n\nNote that `tensorflow-gpu` version can be used instead if a GPU device is available on the system, which will speedup the results.\n\nUSAGE\n#####\n\nThe following example illustrates the ease of use of this package:\n\n\n.. code:: python\n\n    >>> from mtcnn import MTCNN\n    >>> import cv2\n    >>>\n    >>> img = cv2.cvtColor(cv2.imread(\"ivan.jpg\"), cv2.COLOR_BGR2RGB)\n    >>> detector = MTCNN()\n    >>> detector.detect_faces(img)\n    [\n        {\n            'box': [277, 90, 48, 63],\n            'keypoints':\n            {\n                'nose': (303, 131),\n                'mouth_right': (313, 141),\n                'right_eye': (314, 114),\n                'left_eye': (291, 117),\n                'mouth_left': (296, 143)\n            },\n            'confidence': 0.99851983785629272\n        }\n    ]\n\nThe detector returns a list of JSON objects. Each JSON object contains three main keys: 'box', 'confidence' and 'keypoints':\n\n- The bounding box is formatted as [x, y, width, height] under the key 'box'.\n- The confidence is the probability for a bounding box to be matching a face.\n- 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).\n\nAnother good example of usage can be found in the file \"`example.py`_.\" located in the root of this repository. Also, you can run the Jupyter Notebook \"`example.ipynb`_\" for another example of usage.\n\nBENCHMARK\n=========\n\nThe following tables shows the benchmark of this mtcnn implementation running on an `Intel i7-3612QM CPU @ 2.10GHz <https://www.cpubenchmark.net/cpu.php?cpu=Intel+Core+i7-3612QM+%40+2.10GHz>`_, with a **CPU-based** Tensorflow 1.4.1.\n\n - Pictures containing a single frontal face:\n\n+------------+--------------+---------------+-----+\n| Image size | Total pixels | Process time  | FPS |\n+============+==============+===============+=====+\n| 460x259    | 119,140      | 0.118 seconds | 8.5 |\n+------------+--------------+---------------+-----+\n| 561x561    | 314,721      | 0.227 seconds | 4.5 |\n+------------+--------------+---------------+-----+\n| 667x1000   | 667,000      | 0.456 seconds | 2.2 |\n+------------+--------------+---------------+-----+\n| 1920x1200  | 2,304,000    | 1.093 seconds | 0.9 |\n+------------+--------------+---------------+-----+\n| 4799x3599  | 17,271,601   | 8.798 seconds | 0.1 |\n+------------+--------------+---------------+-----+\n\n - Pictures containing 10 frontal faces:\n\n+------------+--------------+---------------+-----+\n| Image size | Total pixels | Process time  | FPS |\n+============+==============+===============+=====+\n| 474x224    | 106,176      | 0.185 seconds | 5.4 |\n+------------+--------------+---------------+-----+\n| 736x348    | 256,128      | 0.290 seconds | 3.4 |\n+------------+--------------+---------------+-----+\n| 2100x994   | 2,087,400    | 1.286 seconds | 0.7 |\n+------------+--------------+---------------+-----+\n\nMODEL\n#####\n\nBy default the MTCNN bundles a face detection weights model.\n\nThe model is adapted from the Facenet's MTCNN implementation, merged in a single file located inside the folder 'data' relative\nto the module's path. It can be overriden by injecting it into the MTCNN() constructor during instantiation.\n\nThe 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.\n\nFor more reference about the network definition, take a close look at the paper from *Zhang et al. (2016)* [ZHANG2016]_.\n\nLICENSE\n#######\n\n`MIT License`_.\n\n\nREFERENCE\n=========\n\n.. [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\u20131503.\n\n.. _example.py: example.py\n.. _example.ipynb: example.ipynb\n.. _MIT license: LICENSE\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Multi-task Cascaded Convolutional Neural Networks for Face Detection, based on TensorFlow",
    "version": "0.1.1",
    "split_keywords": [
        "mtcnn",
        "face",
        "detection",
        "tensorflow",
        "pip",
        "package"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "09d12a4269e387edb97484157b872fa8a1953b53dcafbe4842a1967f549ac5ea",
                "md5": "c67dc1683ab950e64e8e9394c59bc7b7",
                "sha256": "fd69d2f4dd10647dd7481a53b9586e805f35a17c61ac78ba472a7f53766eb86e"
            },
            "downloads": -1,
            "filename": "mtcnn-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c67dc1683ab950e64e8e9394c59bc7b7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 2260416,
            "upload_time": "2021-07-09T11:16:39",
            "upload_time_iso_8601": "2021-07-09T11:16:39.058504Z",
            "url": "https://files.pythonhosted.org/packages/09/d1/2a4269e387edb97484157b872fa8a1953b53dcafbe4842a1967f549ac5ea/mtcnn-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ef11d549caa104ac2a03b6ef32bfca841ebb04c99ddf704b197c272bcdec054d",
                "md5": "bea6a6cd819651d77ea0793575efb7f9",
                "sha256": "d0957274584be62cb83d4a089041f8ee3cf3b1893e45f01ed3356f94a381302b"
            },
            "downloads": -1,
            "filename": "mtcnn-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "bea6a6cd819651d77ea0793575efb7f9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 2256658,
            "upload_time": "2021-07-09T11:16:46",
            "upload_time_iso_8601": "2021-07-09T11:16:46.842789Z",
            "url": "https://files.pythonhosted.org/packages/ef/11/d549caa104ac2a03b6ef32bfca841ebb04c99ddf704b197c272bcdec054d/mtcnn-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-07-09 11:16:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "ipazc",
    "github_project": "mtcnn",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "keras",
            "specs": [
                [
                    ">=",
                    "2.0.0"
                ]
            ]
        },
        {
            "name": "opencv-python",
            "specs": [
                [
                    ">=",
                    "4.1.0"
                ]
            ]
        }
    ],
    "lcname": "mtcnn"
}
        
Elapsed time: 0.04607s