cc1234
commited on
Commit
Β·
2e8f987
1
Parent(s):
3e3b9fc
docs: add CLAUDE.md for project guidance and setup instructions
Browse files
CLAUDE.md
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# CLAUDE.md
|
2 |
+
|
3 |
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
4 |
+
|
5 |
+
## Project Overview
|
6 |
+
|
7 |
+
Stashface is a Python-based face recognition application that identifies performers in images using ensemble machine learning models.
|
8 |
+
It provides a Gradio web interface for uploading images and searching for performer matches against a database of known performers.
|
9 |
+
|
10 |
+
## Common Commands
|
11 |
+
|
12 |
+
### Installation and Setup
|
13 |
+
```bash
|
14 |
+
uv install # Install dependencies using uv package manager
|
15 |
+
```
|
16 |
+
|
17 |
+
### Running the Application
|
18 |
+
```bash
|
19 |
+
python app.py # Launch the Gradio web interface on localhost:7860
|
20 |
+
```
|
21 |
+
|
22 |
+
### Testing
|
23 |
+
```bash
|
24 |
+
pytest tests/ # Run all tests
|
25 |
+
pytest tests/test_vtt_parser.py # Run specific test file
|
26 |
+
```
|
27 |
+
|
28 |
+
### Environment Variables
|
29 |
+
- `DEEPFACE_HOME`: Set to "." (current directory) for DeepFace model storage
|
30 |
+
- `CUDA_VISIBLE_DEVICES`: Set to "-1" to force CPU usage
|
31 |
+
- `VISAGE_KEY`: Required for decrypting performer database in persons.zip
|
32 |
+
|
33 |
+
## Architecture
|
34 |
+
|
35 |
+
### Core Components
|
36 |
+
|
37 |
+
1. **DataManager** (`models/data_manager.py`): Handles loading and querying face recognition data
|
38 |
+
- Manages encrypted performer database (`data/persons.zip`)
|
39 |
+
- Loads face embeddings from JSON (`data/faces.json`)
|
40 |
+
- Handles Voyager vector indices for FaceNet and ArcFace models
|
41 |
+
|
42 |
+
2. **EnsembleFaceRecognition** (`models/face_recognition.py`): Implements ensemble face recognition
|
43 |
+
- Combines FaceNet512 and ArcFace models using weighted voting
|
44 |
+
- Normalizes distances and computes confidence scores
|
45 |
+
- Uses DeepFace backend for face detection and embedding extraction
|
46 |
+
|
47 |
+
3. **WebInterface** (`web/interface.py`): Gradio-based web interface
|
48 |
+
- Two main tabs: Multiple Face Search and Faces in Sprite
|
49 |
+
- Handles image uploads and displays JSON results
|
50 |
+
- Integrates with image processing pipeline
|
51 |
+
|
52 |
+
4. **Image Processing** (`models/image_processor.py`): Core image processing logic
|
53 |
+
- Extracts faces using YOLOv8 and MediaPipe detectors
|
54 |
+
- Generates embeddings for original and horizontally flipped images
|
55 |
+
- Returns performer information with confidence scores
|
56 |
+
|
57 |
+
### Data Flow
|
58 |
+
|
59 |
+
1. User uploads image through Gradio interface
|
60 |
+
2. Face detection extracts individual faces from image
|
61 |
+
3. Face embeddings generated using ensemble models (FaceNet + ArcFace)
|
62 |
+
4. Embeddings queried against Voyager vector indices
|
63 |
+
5. Results ranked by confidence and returned with performer metadata
|
64 |
+
|
65 |
+
### Key Dependencies
|
66 |
+
|
67 |
+
- **DeepFace**: Face recognition and embedding extraction
|
68 |
+
- **Gradio**: Web interface framework
|
69 |
+
- **Voyager**: Vector similarity search indices
|
70 |
+
- **MediaPipe**: Alternative face detection backend
|
71 |
+
- **PyZipper**: Encrypted ZIP file handling for performer database
|
72 |
+
- **UV**: Modern Python package manager
|
73 |
+
|
74 |
+
## File Structure
|
75 |
+
|
76 |
+
```
|
77 |
+
stashface/
|
78 |
+
βββ app.py # Main application entry point
|
79 |
+
βββ data/ # Face recognition data files
|
80 |
+
β βββ faces.json # Face metadata
|
81 |
+
β βββ persons.zip # Encrypted performer database
|
82 |
+
β βββ *.voy # Voyager vector indices
|
83 |
+
βββ models/ # Core ML models and data handling
|
84 |
+
β βββ data_manager.py # Data loading and querying
|
85 |
+
β βββ face_recognition.py # Ensemble face recognition
|
86 |
+
β βββ image_processor.py # Image processing pipeline
|
87 |
+
βββ web/ # Web interface
|
88 |
+
β βββ interface.py # Gradio interface
|
89 |
+
βββ utils/ # Utility functions
|
90 |
+
β βββ vtt_parser.py # VTT file parsing for video sprites
|
91 |
+
βββ tests/ # Test files
|
92 |
+
```
|
93 |
+
|
94 |
+
## Development Notes
|
95 |
+
|
96 |
+
- The application uses CPU-only inference (CUDA disabled via environment variable)
|
97 |
+
- Face embeddings are averaged between original and horizontally flipped images for better accuracy
|
98 |
+
- The performer database is encrypted and requires the `VISAGE_KEY` environment variable
|
99 |
+
- Vector indices use E4M3 storage format for memory efficiency
|
100 |
+
- The ensemble approach combines FaceNet512 and ArcFace models with equal weighting (1.0 each)
|