Multitask Cascaded Convolutional Networks for face detection and alignment (MTCNN) in Python >= 3.10 and TensorFlow >= 2.12
pip install mtcnnMTCNN - Multitask Cascaded Convolutional Networks for Face Detection and Alignment
Overview

MTCNN is a robust face detection and alignment library implemented for Python >= 3.10 and TensorFlow >= 2.12, designed to detect faces and their landmarks using a multitask cascaded convolutional network. This library improves on the original implementation by offering a complete refactor, simplifying usage, improving performance, and providing support for batch processing.
This library is ideal for applications requiring face detection and alignment, with support for both bounding box and landmark prediction.
Installation
MTCNN can be installed via pip:
pip install mtcnn
MTCNN requires Tensorflow >= 2.12. This external dependency can be installed manually or automatically along with MTCNN via:
pip install mtcnn[tensorflow]
Usage Example
from mtcnn import MTCNN
from mtcnn.utils.images import load_image
# Create a detector instance
detector = MTCNN(device="CPU:0")
# Load an image
image = load_image("ivan.jpg")
# Detect faces in the image
result = detector.detect_faces(image)
# Display the result
print(result)
Output example:
[
{
"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.9985
}
]
Models Overview
MTCNN uses a cascade of three networks to detect faces and facial landmarks:
- PNet (Proposal Network): Scans the image and proposes candidate face regions.