This project provides a backend for a face recognition application, using FastAPI, Prisma ORM for PostgreSQL, and Milvus for vector database storage and similarity search. DeepFace is used for facial recognition and embedding extraction.
- Employee registration with face embedding storage.
- Visitor registration with face embedding storage.
- Face recognition for employees and visitors.
- Integration with Prisma (PostgreSQL) for structured data storage.
- Integration with Milvus for vector similarity search.
- Preloading of DeepFace model for optimized performance.
- Python 3.9+
- PostgreSQL
- Milvus
- Node.js (for Prisma migrations)
Create a .env
file with the following variables:
DATABASE_URL=postgresql://user:password@localhost:5432/database_name
MILVUS_HOST=localhost
MILVUS_PORT=19530
Install the required Python packages:
pip install fastapi uvicorn prisma pymilvus deepface Pillow numpy python-dotenv pytz
GET /
Description: Test endpoint to verify the server is running.
Response:
{"message": "Face App Backend"}
POST /register-employee/
Description: Register a new employee with personal details and face embedding.
Form Data:
name
: Employee name (string)age
: Employee age (integer)gender
: Employee gender (string)photo
: Employee photo (file)designation
: Job designation (string)contactNumber
: Contact number (string)department
: Department (string)description
: Additional description (string)
Response:
{"message": "Employee registered successfully."}
POST /register-visitor/
Description: Register a visitor with personal details and face embedding.
Form Data:
name
: Visitor name (string)age
: Visitor age (integer)gender
: Visitor gender (string)photo
: Visitor photo (file)contact
: Contact number (string)purposeOfVisit
: Purpose of the visit (string)description
: Additional description (string)
Response:
{"message": "Visitor registered successfully."}
POST /recognize-employee/
Description: Recognize an employee from a photo.
Form Data:
photo
: Uploaded photo (file)
Response:
If a match is found:
{"name": "John Doe", "similarity": 0.85, "status": "success"}
If no match is found:
{"message": "No match found", "status": "failed"}
POST /recognize-visitor/
Description: Recognize a visitor from a photo.
Form Data:
photo
: Uploaded photo (file)
Response:
If a match is found:
{"name": "Jane Doe", "similarity": 0.90, "status": "success"}
If no match is found:
{"message": "No match found", "status": "failed"}
- Framework for building the backend.
- Provides routing, middleware, and dependency injection.
- Manages structured data in PostgreSQL.
- Used to store:
- Employee details
- Visitor details
- Vector database for storing face embeddings.
- Used for similarity searches.
- Extracts facial embeddings.
- Model used: VGG-Face.
Column | Type | Description |
---|---|---|
id |
UUID | Primary key |
name |
String | Employee name |
age |
Integer | Employee age |
gender |
String | Employee gender |
photoBase64 |
Text | Base64-encoded photo |
designation |
String | Job designation |
contactNumber |
String | Contact number |
department |
String | Department |
description |
String | Additional description |
Column | Type | Description |
---|---|---|
id |
UUID | Primary key |
name |
String | Visitor name |
age |
Integer | Visitor age |
gender |
String | Visitor gender |
photoBase64 |
Text | Base64-encoded photo |
contact |
String | Contact number |
purposeOfVisit |
String | Purpose of the visit |
description |
String | Additional description |
-
extract_face_embedding(photo_bytes: bytes)
- Extracts face embedding from photo bytes using DeepFace.
- Returns a 4096-dimensional embedding.
-
save_to_milvus(collection_name, name, embedding)
- Saves normalized embeddings to Milvus.
-
search_in_milvus(collection_name, query_embedding, threshold=0.6)
- Searches Milvus for a match to the query embedding.
- Returns the best match if similarity exceeds the threshold.
-
save_to_prisma(name, age, gender, photo_base64, table, additional_data)
- Saves user details to PostgreSQL using Prisma ORM.
uvicorn main:app --reload
- Swagger UI: http://127.0.0.1:8000/docs
- Implement rate limiting for API endpoints.
- Add authentication and authorization.
- Use GPU acceleration for faster embedding extraction.
- Integrate more facial recognition models.
- Rate limiter for requests
- Authentication
- Session using redux and redux tools (setting up store and auth-sessions)
- Form validations
- Pydantics models for Proper models