A package for analyzing faces in images to detect eye state, gaze direction, and facial expressions
Project description
Face Analysis Kit
A Python package for analyzing faces in images to detect eye state, gaze direction, and facial expressions.
Features
- Gaze Detection: Determine gaze direction using ResNet models
- Eye State Classification: Detect whether eyes are open or closed
- Emotion Recognition: Identify facial expressions and emotions
How to install:
1. Install from PyPI
pip install face_analysis_kit
2. Build and install from source
- Clone the repo
git clone https://github.com/ahmedsalim3/face-analysis.git
cd face-analysis
- Create a virtual environment and install dependencies:
make install
This will:
- Install all dependencies using
uv - Set up pre-commit hooks for code quality
- Activate the environment:
source .venv/bin/activate
Optional: Install the package in editable mode pip install -e .
Usage Examples
Command Line Interface
The package provides several command-line tools for analyzing faces in images:
- Analyze a single image:
bash scripts/run_analysis.sh single input/test_1.png
- Analyze all images in a folder:
bash scripts/run_analysis.sh folder input/
- Select the best image from a folder:
bash scripts/run_analysis.sh best input/
Output will be saved to output/<command>/ directory.
Python API
Gaze Detection
from face_analysis.gazes import Pipeline as GazesPipeline
from face_analysis.gazes import render as GazesRender
gaze_pipeline = GazesPipeline(
arch='ResNet50', # Options: "ResNet18", "ResNet34", "ResNet101", "ResNet152"
detector="retinaface", # Options: "mtcnn"
device="cuda", # or "cpu"
)
img_in = cv2.imread("input/test_1.png")
results = gaze_pipeline.step(img_in)
img_out = GazesRender(img_in, results)
Eye State Detection
from face_analysis.eyes import Pipeline as EyesPipeline
from face_analysis.eyes import render as eyes_render
eye_pipeline = EyesPipeline(
detector="retinaface", # or "dlib"
device="cpu", # or "cuda"
)
img_in = cv2.imread(img_path)
results = eye_pipeline.step(img_in)
img_out = eyes_render(img_in, results)
Emotion Detection
from face_analysis.emotions import Pipeline as EmotionsPipeline
from face_analysis.emotions import render as emotions_render
emotion_pipeline = EmotionsPipeline(
detector= "retinaface", # or "mtcnn", or "cascade"
device= "cpu",
)
img_in = cv2.imread(img_path)
results = emotion_pipeline.step(img_in)
img_out = emotions_render(img_in, results)
Repo Structure
project_root/
├── data/
├── input/
├── output/
├── scripts/
├── face_analysis/
│
├── LICENSE.txt
├── pyproject.toml
├── README.md
├── requirements.txt
├── uv.lock
└── Makefile
Contributing
Contributions are welcome! Please fork the repository, make your changes, and submit a pull request.
make install # to setup environment and hooks
make test # to run tests before submitting
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file face_analysis_kit-0.1.4.tar.gz.
File metadata
- Download URL: face_analysis_kit-0.1.4.tar.gz
- Upload date:
- Size: 13.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e5fa0ef10c011bdfed94a77d53c819449fe84a3bbb843c3c0e0779ecb591c71
|
|
| MD5 |
b7c0c6c7335e8bd2624fa994f117d298
|
|
| BLAKE2b-256 |
e1b30514283969dc8c7f4358b6eddb259fa6b475b70934786366c3f7f2eb7e14
|
File details
Details for the file face_analysis_kit-0.1.4-py3-none-any.whl.
File metadata
- Download URL: face_analysis_kit-0.1.4-py3-none-any.whl
- Upload date:
- Size: 1.5 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cab4e02b1ad3d0e821a7620b5e24ca87419bf8e6b474aba4f3fda52af38ad15e
|
|
| MD5 |
5ca2af7c804ffeb2b989a651c6aed15f
|
|
| BLAKE2b-256 |
397beb687f3ff66462111947010064a372a516b207c42cf70c7ef039f7b74fdd
|