feat(compare): add face comparison functionality with cosine similarity
Some checks failed
build / checks-matrix (push) Successful in 19m23s
build / codecov (push) Failing after 19m18s
docs / docs (push) Failing after 28m50s
build / checks-build (push) Has been cancelled

This commit is contained in:
uttarayan21
2025-08-21 17:34:07 +05:30
parent f8122892e0
commit bfa389b497
15 changed files with 1188 additions and 107 deletions

View File

@@ -55,6 +55,35 @@ cargo run --release detect --output detected.jpg path/to/image.jpg
cargo run --release detect --threshold 0.9 --nms-threshold 0.4 path/to/image.jpg
```
### Face Comparison
Compare faces between two images by computing and comparing their embeddings:
```bash
# Compare faces in two images
cargo run --release compare image1.jpg image2.jpg
# Compare with custom thresholds
cargo run --release compare --threshold 0.9 --nms-threshold 0.4 image1.jpg image2.jpg
# Use ONNX Runtime backend for comparison
cargo run --release compare -p cpu image1.jpg image2.jpg
# Use MNN with Metal acceleration
cargo run --release compare -f metal image1.jpg image2.jpg
```
The compare command will:
1. Detect all faces in both images
2. Generate embeddings for each detected face
3. Compute cosine similarity between all face pairs
4. Display similarity scores and the best match
5. Provide interpretation of the similarity scores:
- **> 0.8**: Very likely the same person
- **0.6-0.8**: Possibly the same person
- **0.4-0.6**: Unlikely to be the same person
- **< 0.4**: Very unlikely to be the same person
### Backend Selection
The project supports two inference backends:
@@ -106,7 +135,7 @@ The MNN backend supports various execution backends:
- **CPU** - Default, works on all platforms
- **Metal** - macOS GPU acceleration
- **CoreML** - macOS/iOS neural engine acceleration
- **CoreML** - macOS/iOS neural engine acceleration
- **OpenCL** - Cross-platform GPU acceleration
```bash
@@ -179,7 +208,7 @@ MIT License
Key dependencies include:
- **MNN** - High-performance neural network inference framework (MNN backend)
- **ONNX Runtime** - Cross-platform ML inference (ORT backend)
- **ONNX Runtime** - Cross-platform ML inference (ORT backend)
- **ndarray** - N-dimensional array processing
- **image** - Image processing and I/O
- **clap** - Command line argument parsing