FaceMatch is an AI-powered Django application that uses the DeepFace library to find facial similarities by comparing image embeddings. The project offers two endpoints: one for saving user images as embeddings and another for comparing a given image against saved embeddings to find a matching face. This tool is ideal for applications such as identity verification, duplicate detection, or face matching in various organizational contexts.
- Facial Embedding Generation: Converts uploaded images into numerical embeddings using deep learning models.
- Face Similarity Comparison: Compares new images with stored embeddings to find similar faces, providing a similarity score.
- Multiple Model Support: Leverages various models like Facenet, VGG-Face, and others from the DeepFace library.
- Organizational Segmentation: Manages embeddings on a per-organization basis for better data isolation.
- Backend: Django, Django REST Framework
- Machine Learning: DeepFace for facial recognition
- Database: SQLite (default) or any other supported by Django ORM
-
Clone the repository:
git clone https://github.com/your-username/FaceMatch.git cd FaceMatch
-
Set up a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Apply migrations:
python manage.py migrate
-
Run the server:
python manage.py runserver
- URL:
/api/embeddings/
- Method:
POST
- Description: Saves images for a specific organization and generates embeddings.
- Request:
{ "organization": "string", "images": [file] }
- Response:
{ "embed_id": "integer", "organization": "string", "embedding": "string", "created_at": "datetime" }
- URL:
/api/face-compare/
- Method:
POST
- Description: Compares an uploaded image with the saved embeddings for a specific organization.
- Request:
{ "organization": "string", "image": file }
- Response:
{ "embed_id": "integer", "similarity_score": "float" }
- views.py: Contains API views for embedding generation and face comparison.
- services.py: Handles core logic for embedding generation, comparison, and utility functions for processing images.
- utils.py: Provides helper functions for saving images, embedding processing, and finding similar faces.
- models.py: Defines database models for storing embeddings and associated image metadata.
- serializers.py: Serializes input data for the API endpoints.
To save embeddings for an organization, send a POST
request to /api/embeddings/
with the following body:
curl -X POST http://localhost:8000/api/embeddings/ \
-F "organization=MyOrganization" \
-F "images=@/path/to/image1.jpg" \
-F "images=@/path/to/image2.jpg"
To compare a face, send a POST request to /api/face-compare/:
curl -X POST http://localhost:8000/api/face-compare/ \
-F "organization=MyOrganization" \
-F "image=@/path/to/query_image.jpg"
Feel free to open issues or submit pull requests for improvements. Contributions to enhance functionality or fix bugs are always welcome.