File size: 2,237 Bytes
1cb32b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---
title: Face Recognition System
emoji: 👤
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 4.0.0
app_file: app.py
pinned: false
license: mit
short_description: A face recognition system using Siamese networks and cosine similarity
---

# Face Recognition System

A comprehensive face recognition system that can compare faces for similarity and classify faces into different categories.

## Features

- **Face Similarity Comparison**: Compare two face images and get a similarity score
- **Face Classification**: Classify a single face image into predefined categories
- **Cosine Similarity**: Uses advanced cosine similarity for accurate face matching
- **Siamese Neural Network**: Leverages deep learning for robust feature extraction

## How to Use

### Face Similarity
1. Upload two face images
2. Click "Compare Faces"
3. Get a similarity score and interpretation

### Face Classification
1. Upload a single face image
2. Click "Classify Face"
3. Get the predicted face class

## Similarity Score Interpretation

- **0.8-1.0**: Very High Similarity (likely same person)
- **0.6-0.8**: High Similarity (possibly same person)
- **0.4-0.6**: Moderate Similarity (uncertain)
- **0.2-0.4**: Low Similarity (likely different persons)
- **0.0-0.2**: Very Low Similarity (definitely different persons)

## Technical Details

- **Model**: Siamese Neural Network with CNN layers
- **Similarity Metric**: Cosine Similarity
- **Classifier**: K-Nearest Neighbors
- **Preprocessing**: StandardScaler normalization
- **Input Size**: 100x100 pixels (grayscale)

## API Usage

The system also provides API endpoints:

### Similarity API
```bash
curl -X POST \
  -F "file1=@face1.jpg" \
  -F "file2=@face2.jpg" \
  https://pavaniyerra-hackthon4.hf.space/predict_similarity/
```

### Classification API
```bash
curl -X POST \
  -F "file=@face.jpg" \
  https://pavaniyerra-hackthon4.hf.space/predict_class/
```

## Requirements

- Python 3.11
- PyTorch
- OpenCV
- scikit-learn==1.6.1
- Gradio
- NumPy
- Pillow
- Joblib

## Model Files

The system requires these trained model files:
- `siamese_model.t7`: Trained Siamese network
- `decision_tree_model.sav`: KNN classifier
- `face_recognition_scaler.sav`: StandardScaler for normalization