CONFIDENCE_THRESHOLD = 0.55- Minimum similarity score to consider a matchMIN_DETECTION_SCORE = 0.85- Minimum face detection confidenceMIN_FACE_SIZE = 80- Minimum face size in pixels
VERIFICATION_COUNT = 3- Number of consistent detections required before marking attendanceCOOLDOWN_SECONDS = 600- Cooldown period (10 minutes) to prevent duplicate entries
FRAME_CAPTURE_INTERVAL = 2.0- Capture and process frame every 2 secondsVIDEO_FPS = 30- Target FPS for smooth video displayVIDEO_WIDTH = 1280- Ideal camera resolution widthVIDEO_HEIGHT = 720- Ideal camera resolution height
GPU_BATCH_SIZE = 5- Number of frames to process in batch on GPU- Uses
CUDAExecutionProviderfor NVIDIA GPU acceleration - Automatically falls back to CPU if GPU not available
CACHE_SYNC_INTERVAL = 3600- Sync cache with Pinecone every hour (3600 seconds)- Cache file:
embeddings_cache.jsonin backend root - Cache queries first, Pinecone as fallback
app/services/embedding_cache.py- Local vector cache with cosine similarity searchapp/services/face_embedding.py- GPU-accelerated face detection and embeddingapp/core/startup.py- Initialization: GPU check, model warmup, cache syncapp/api/identify.py- Face identification endpoint with cache-first lookupapp/main.py- FastAPI app with verification buffer and startup events
components/attendance-camera.tsx- Browser-native camera with 30 FPS displayapp/teacher/timetable/page.tsx- Attendance interface using camera component
-
POST /identify/- Identify faces from uploaded image- Form data:
file(image),session_id(optional) - Returns: List of detected faces with bounding boxes and identifications
- Form data:
-
POST /identify/webcam- Identify faces from webcam capture- Returns: Same as above
GET /health- System status and statistics- Returns: GPU status, cache stats, active sessions
| Metric | Target | Notes |
|---|---|---|
| Video FPS | 30 | Smooth display without stuttering |
| Detection latency | <100ms | With GPU acceleration |
| Recognition latency | <50ms | Using local cache |
| Cache hit rate | >90% | Most queries from cache |
| GPU utilization | 40-60% | During active recognition |
| False positive rate | <1% | With 3-detection verification |
- GPU Verification - Check CUDA availability and log device info
- Model Initialization - Load InsightFace models with GPU provider
- Model Warmup - Run dummy inference to load models into GPU memory
- Cache Sync - Fetch all embeddings from Pinecone to local cache
- Ready - System ready for face recognition
- Face detected → Extract embedding
- Query local cache first (fast)
- If cache miss → Query Pinecone (fallback)
- If match found → Add to verification buffer
- After 3 consistent detections → Check cooldown
- If no recent attendance → Mark attendance
- Clear buffer for that student
- Session-based tracking: Students tracked per session
- Cooldown enforcement: 10-minute minimum between marks
- Buffer clearing: Prevents re-marking same student
- Check
nvidia-smiin terminal - Verify PyTorch CUDA installation:
pip install torch --index-url https://download.pytorch.org/whl/cu118 - Check startup logs for GPU detection
- Check
embeddings_cache.jsonexists in backend root - Verify Pinecone connection during startup
- Check logs for "Cache hit" vs "Pinecone fallback" messages
- Ensure
FRAME_CAPTURE_INTERVALis 2.0+ seconds - Check GPU utilization (should be 40-60%)
- Reduce
VERIFICATION_COUNTif too many frames queued
- Verify
COOLDOWN_SECONDSis set to 600 - Check
marked_studentsdictionary is being maintained - Review verification buffer logic in logs
Add to .env file in backend:
# Pinecone
PINECONE_API_KEY=your_api_key
PINECONE_INDEX_NAME=your_index_name
# GPU (optional)
CUDA_VISIBLE_DEVICES=0 # Use first GPU
# Logging
LOG_LEVEL=INFOpip install torch torchvision --index-url https://download.pytorch.org/whl/cu118
pip install insightface onnxruntime-gpu fastapi uvicorn opencv-python numpy pinecone-clientnpm installcd backend
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000cd frontend
npm run devnvidia-smi -l 1 # Update every secondcurl http://localhost:8000/healthBackend logs will show:
- GPU detection results
- Cache hits/misses
- Verification buffer activity
- Attendance marking events