Skip to content

Commit

Permalink
tf-keras added to requirements & created Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
fazliddindehkanoff committed Oct 16, 2024
1 parent d2a3f20 commit b58468a
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 1 deletion.
118 changes: 118 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# FaceMatch

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.

## Features

- **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.

## Tech Stack

- **Backend**: Django, Django REST Framework
- **Machine Learning**: DeepFace for facial recognition
- **Database**: SQLite (default) or any other supported by Django ORM

## Installation

1. **Clone the repository**:
```bash
git clone https://github.com/your-username/FaceMatch.git
cd FaceMatch
```

2. **Set up a virtual environment**:
```bash
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
```

3. **Install dependencies**:
```bash
pip install -r requirements.txt
```

4. **Apply migrations**:
```bash
python manage.py migrate
```

5. **Run the server**:
```bash
python manage.py runserver
```

## API Endpoints

### 1. Embedding Endpoint
- **URL**: `/api/embeddings/`
- **Method**: `POST`
- **Description**: Saves images for a specific organization and generates embeddings.
- **Request**:
```json
{
"organization": "string",
"images": [file]
}
```
- **Response**:
```json
{
"embed_id": "integer",
"organization": "string",
"embedding": "string",
"created_at": "datetime"
}
```

### 2. Face Comparison Endpoint
- **URL**: `/api/face-compare/`
- **Method**: `POST`
- **Description**: Compares an uploaded image with the saved embeddings for a specific organization.
- **Request**:
```json
{
"organization": "string",
"image": file
}
```
- **Response**:
```json
{
"embed_id": "integer",
"similarity_score": "float"
}
```

## Project Structure

- **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.

## Example Usage

### Save Embeddings
To save embeddings for an organization, send a `POST` request to `/api/embeddings/` with the following body:
```bash
curl -X POST http://localhost:8000/api/embeddings/ \
-F "organization=MyOrganization" \
-F "images=@/path/to/image1.jpg" \
-F "images=@/path/to/image2.jpg"
```
### Compare Faces
To compare a face, send a POST request to /api/face-compare/:

```bash
curl -X POST http://localhost:8000/api/face-compare/ \
-F "organization=MyOrganization" \
-F "image=@/path/to/query_image.jpg"
```

## Contributing

Feel free to open issues or submit pull requests for improvements. Contributions to enhance functionality or fix bugs are always welcome.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
deepface==0.0.93
Django==5.1.2
djangorestframework==3.15.2
djangorestframework==3.15.2
tf-keras==2.17.0

0 comments on commit b58468a

Please sign in to comment.