Registry / ai-ml / face-recognition

face-recognition

JSON →
library1.3.0pypypiunverified

face-recognition is a Python library that provides a straightforward API for facial detection, facial landmark localization, and face recognition from images and video. It leverages dlib's state-of-the-art deep learning models for high accuracy and offers both Python module and command-line interfaces. The current version is 1.3.0, and releases occur periodically to add features, improve performance, and address compatibility issues, often tied to its core dependency, dlib.

pip install face-recognition
INSTALL
IMPORT
SIG · FACE-RECOGNITION
F
face-recognition
ai-mlpythonv1.3.0
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

face_recognition
import face_recognition

This quickstart demonstrates how to load an image and find all faces within it, returning their bounding box coordinates. It also shows how to locate key facial features (landmarks) like eyes, nose, and mouth. Ensure you have an image file named `my_picture.jpg` in the same directory as your script, or update the path accordingly.

import face_recognition import os # Create a dummy image file for demonstration # In a real scenario, you would load an actual image. # You can replace 'my_picture.jpg' with a path to your own image. # For example, download one from the internet and save it. if not os.path.exists('my_picture.jpg'): print("Please provide a 'my_picture.jpg' file in the current directory for the quickstart example.") # Exit or create a placeholder if it's strictly necessary for execution, but for a quickstart, it's better to tell user to provide one. # For a truly runnable example without external files, one might generate a blank image or use base64 encoded data, but it complicates the quickstart. exit() image = face_recognition.load_image_file("my_picture.jpg") face_locations = face_recognition.face_locations(image) print(f"Found {len(face_locations)} face(s) in this image.") for face_location in face_locations: top, right, bottom, left = face_location print(f"A face is located at pixel location Top: {top}, Left: {left}, Bottom: {bottom}, Right: {right}") # To demonstrate facial landmarks (eyes, nose, mouth, etc.) face_landmarks_list = face_recognition.face_landmarks(image) for face_landmarks in face_landmarks_list: print("Facial features for a face:") for facial_feature in face_landmarks.keys(): print(f"- The {facial_feature} in this face has the following points: {face_landmarks[facial_feature]}")
face_recognition --version
Debug
Known issues
gotchaInstalling the `dlib` dependency, which is written in C++, is often complex and prone to errors, especially on Windows or certain Linux distributions. It typically requires CMake and C++ build tools (e.g., Visual Studio Build Tools on Windows, `build-essential` on Linux).
fix
Before `pip install face-recognition`, ensure CMake is installed and in your system PATH, and that C++ development tools are properly set up for your OS. It's often recommended to `pip install cmake` and `pip install dlib` separately before `pip install face-recognition`. Consider using a virtual environment.
affects: All versions
breakingSome Python versions, particularly newer ones like 3.11+, may experience installation issues with `dlib` (and by extension `face-recognition`) due to `dlib`'s reliance on legacy `setup.py` build mechanisms.
fix
Consider using Python 3.9 or 3.10 if encountering persistent build errors. Alternatively, try installing a pre-compiled `dlib` wheel (`.whl` file) compatible with your Python version and OS before installing `face-recognition`.
affects: Python 3.11+
gotchaDeployment to cloud hosting providers (e.g., Heroku, AWS, Streamlit Cloud) can be challenging because `dlib`'s compilation requires significant RAM, often exceeding default limits (e.g., 1GB on Streamlit Cloud) and resulting in Out-Of-Memory (OOM) errors.
fix
For cloud deployments, consider using a Docker image with pre-compiled `dlib` and `face-recognition`, or a `dlib-bin` package (if available) as a dependency. Some users have found success by forking the repository and replacing the `dlib` dependency with `dlib-bin` in `setup.py`.
affects: All versions
gotchaThe `face-recognition` library's model is primarily trained on adult faces and may not perform optimally or accurately when recognizing children.
fix
Be aware of this limitation when applying the library to datasets containing children. Custom training or fine-tuning on child-specific datasets would be required for better performance, but this is beyond the scope of this library's direct functionality.
affects: All versions
Upgrade
Version history
1.3.0latest on PyPI · released Feb 20, 2020
Audit
Dependencies
dlibrequiredCore deep learning library for face detection and recognition algorithms. Its compilation often requires system-level build tools and CMake.
numpyrequiredFundamental package for numerical computation, especially for image array manipulation.
face_recognition_modelsrequiredContains the pre-trained models used by face-recognition. It's often installed automatically but sometimes needs explicit installation.
cmakerequiredRequired for building and installing dlib from source, which pip often attempts during face-recognition installation.
PillowoptionalUsed for image manipulation, particularly for drawing bounding boxes and facial features in examples.
opencv-pythonoptionalRequired for real-time video processing examples and some webcam functionalities.
Agent activity
33 hits · last 30 days
node
30
OpenAI (training)
1
Resources
face-recognition — pip install face-recognition · libregistry