A high-performance face recognition API built with FastAPI and optimized using FAISS for efficient similarity search. This system provides endpoints for registering individuals and recognizing faces in images.
- FastAPI: Modern web framework for building high-performance APIs with Python 3.7+.
- DeepFace: Face recognition framework handling detection and embedding extraction.
- FAISS (Facebook AI Similarity Search): Library for efficient similarity search of dense vectors.
- SQLite: Lightweight database for storing person records and embeddings.
- OpenCV: Image processing and face alignment.
- UVicorn: ASGI server for running the FastAPI application.
fastapi: Web framework.deepface: Face detection and recognition.faiss-cpu/faiss-gpu: Similarity search.numpy: Numerical operations.opencv-python: Image processing.python-multipart: File upload handling.sqlite3: Database integration.
- RetinaFace: High-accuracy face detector.
- ArcFace: State-of-the-art face recognition model.
- GPU Acceleration: FAISS index operations (requires a CUDA-enabled GPU).
- Batch Processing: Efficient handling of multiple face embeddings.
- Conda package manager: Make sure Conda is installed to manage dependencies and virtual environments.
- CUDA-enabled GPU (optional for GPU acceleration): If you want to utilize GPU acceleration, ensure that your GPU supports CUDA. For a guide, refer to the following tutorial:
- Clone the repository:
git clone https://github.com/rikurunico/deepface-restapi.git
cd deepface-restapi- Create the Conda environment:
conda env create -f environment.yml- Activate the environment:
conda activate tf_envPOST /api/v1/persons
- Registers a new person with their face embedding.
- Parameters:
name: The person's name (form data).image: The face image file (JPEG/PNG).
POST /api/v1/recognize
- Recognizes faces in an image.
- Parameters:
image: The image file containing faces.threshold: Similarity threshold (default: 0.6).
curl -X POST -F "name=John Doe" -F "image=@john.jpg" http://localhost:8000/api/v1/personscurl -X POST -F "image=@group_photo.jpg" http://localhost:8000/api/v1/recognizeSample Response:
{
"results": [
{
"confidence": 0.82,
"person": {
"id": "a1b2c3d4-...",
"name": "John Doe",
"created_at": "2023-07-15T10:00:00"
}
}
]
}- GPU Utilization: FAISS index operations are GPU-accelerated.
- Batch Processing: Efficient handling of multiple faces in a single image.
- Cached Embeddings: Pre-loaded embeddings in FAISS index at startup.
- Face Alignment: RetinaFace detector ensures optimal recognition accuracy.
- The first run will download DeepFace models (~500MB).
- Minimum recommended image size: 640x480 pixels.
- Optimal recognition threshold: 0.6-0.7.
- The API automatically handles face alignment and normalization.
This project is licensed under the terms set by the author. Please refer to the LICENSE file for details on usage and permissions.