Production-grade biometric face attendance system with real-time geofencing for Amrita Vishwa Vidyapeetham
Hypersphere Engine is a full-stack, research-to-production attendance platform that combines a deep learning facial recognition pipeline with campus-level GPS geofencing. It was designed for institutional deployment at Amrita Vishwa Vidyapeetham, Ettimadai Campus (Coimbatore, Tamil Nadu) with a focus on privacy, accuracy, and zero user friction.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Kiosk / Web Dashboard โ
โ (Next.js 15 ยท TypeScript ยท Glassmorphic UI) โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโ
โ HTTP POST /api/v1/verify โ iframe
โ HTTP POST /api/v1/register โ postMessage
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FastAPI Backend โ โ Amrita Geofence Map โ
โ (Python ยท Uvicorn) โ โ (Leaflet.js ยท PiP โ
โ โ โ Ray-Casting Engine) โ
โ โโโโโโโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ FacePipeline โ โ
โ โ 1. SCRFD ONNX โ โ
โ โ 2. MediaPipe โ โ
โ โ 3. MiniFASNetV2 โ โ
โ โ 4. ArcFace ONNX โ โ
โ โโโโโโโโโโฌโโโโโโโโโโโโ โ
โ โ 512-D Vector โ
โ โโโโโโโโโโผโโโโโโโโโโโโ โ
โ โ PgVectorIndex โ โ
โ โ PostgreSQL + โ โ
โ โ pgvector โ โ
โ โ (FAISS fallback) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Stage | Technology | Detail |
|---|---|---|
| Face Detection | SCRFD 2.5G (ONNX) | Sub-millisecond detection, returns keypoints for alignment |
| Face Alignment | MediaPipe | 5-point affine warp to canonical 112ร112 face crop |
| Liveness Detection | MiniFASNetV2 (PyTorch) | Blocks printed photos, screen replays, and 3D masks |
| Feature Extraction | ArcFace w600k_r50 (ONNX) | 512-dimensional identity embedding, cosine similarity |
| Identity Verification | 1:1 Verification | Restricts vector search to claimed identity, eliminates cross-identity false accepts |
Every frame passes through strict pre-flight checks before ML inference:
- Illumination โ Rejects underlit frames
- Face Size โ Rejects faces too small for reliable embedding
- Yaw Angle โ Rejects excessive side-profile poses
- Blur Detection โ Rejects motion-blurred captures
- Liveness Score โ Hard threshold at
0.40(MiniFASNetV2 confidence) - Embedding Norm โ Dynamic
EMBEDDING_QUALITY_THRESHOLDcalibrated at boot from existing enrollment distribution
- 103 building polygons extracted from OpenStreetMap via Overpass API
- Ray-Casting PiP algorithm โ determines exact building from GPS coordinates in <1ms
- GPS accuracy enforcement โ rejects IP-based fixes (>100m accuracy), demands hardware GPS
- 3-tier resolution:
Inside BuildingโCampus GroundsโOff Campus - Nearest building computation via Haversine distance when outdoors
- Live webcam stream with face bounding-box overlay
- Enrollment flow with liveness gate and duplicate detection
- Real-time attendance verification with location context
- Admin panel: user management, attendance logs, CSV export
- Dark glassmorphic UI with
Outfit+Plus Jakarta Sanstypography
hypersphere-engine/
โ
โโโ backend/ # FastAPI Python backend
โ โโโ app/
โ โ โโโ api/
โ โ โ โโโ endpoints.py # All API route handlers
โ โ โโโ core/
โ โ โ โโโ pipeline.py # Main ML inference pipeline (FacePipeline)
โ โ โ โโโ scrfd.py # SCRFD ONNX face detector wrapper
โ โ โ โโโ amrita_engine.py # Amrita campus geofence engine
โ โ โ โโโ csv_loader.py # Faculty CSV auto-seeder on boot
โ โ โ โโโ liveness/ # MiniFASNetV2 anti-spoofing module
โ โ โโโ db/
โ โ โ โโโ database.py # SQLAlchemy async engine + table definitions
โ โ โ โโโ vector_index.py # pgvector + FAISS hybrid vector search
โ โ โโโ models/
โ โ โ โโโ schemas.py # Pydantic request/response schemas
โ โ โโโ config.py # Centralised settings (thresholds, paths)
โ โ โโโ main.py # FastAPI app, lifespan hooks, CORS
โ โโโ requirements.txt
โ โโโ run.sh
โ
โโโ nextjs-frontend/ # Next.js 15 TypeScript frontend
โ โโโ app/
โ โ โโโ dashboard/page.tsx # Main kiosk dashboard
โ โ โโโ login/page.tsx # Auth page
โ โ โโโ globals.css # Global design system styles
โ โโโ components/ # Reusable UI components
โ โโโ public/
โ โ โโโ amrita_map.html # Geofencing map (self-contained)
โ โ โโโ amrita_data/ # Campus GeoJSON data files
โ โโโ package.json
โ
โโโ scripts/ # Utility & data scripts
โ โโโ extract_amrita.py # Live OSM extraction for Amrita campus
โ โโโ download_models.py # ONNX model downloader
โ โโโ anti_spoof_test.py # Liveness pipeline testing
โ โโโ embedding_test.py # ArcFace vector similarity tester
โ โโโ amrita_data/ # Raw + processed campus geodata
โ
โโโ models/ # ONNX & PyTorch model weights (gitignored)
โ โโโ scrfd_2.5g_bnkps.onnx
โ โโโ w600k_r50.onnx
โ โโโ 2.7_80x80_MiniFASNetV2.pth
โ
โโโ features/ # Feature registry & developer docs
โ โโโ README.md # Architectural overview & extension guide
โ โโโ 01_biometric_pipeline.md
โ โโโ 02_vector_database.md
โ โโโ 03_quality_gating.md
โ โโโ 04_kiosk_live_demo.md
โ
โโโ docker-compose.yml # PostgreSQL + pgvector + API stack
โโโ Dockerfile
โโโ setup.sh
All tuneable parameters live in backend/app/config.py:
| Setting | Default | Description |
|---|---|---|
MATCH_THRESHOLD |
0.60 |
Minimum cosine similarity to accept a face match. Higher = stricter. |
AMBIGUITY_MARGIN |
0.05 |
Minimum score gap between top-2 matches; prevents ambiguous accepts. |
DETECTION_THRESHOLD |
0.50 |
SCRFD confidence threshold for face detection. |
ANTISPOOF_THRESHOLD |
0.40 |
MiniFASNetV2 live probability; below this = spoofing attempt. |
EMBEDDING_QUALITY_THRESHOLD |
12.0 |
Min L2 norm of embedding; calibrated dynamically at boot from enrollment data. |
DUPLICATE_SEARCH_THRESHOLD |
0.70 |
Similarity above which a new enrollment is flagged as a duplicate identity. |
BBOX_EXPANSION |
2.7 |
Face crop expansion factor for alignment headroom. |
VECTOR_INDEX_PATH |
faiss_vectors.index |
Path to local FAISS fallback index. |
DATABASE_URL |
SQLite (dev) | Set postgresql+asyncpg://... for production. |
- Python 3.10+
- Node.js 18+
- Docker & Docker Compose (for PostgreSQL)
- CUDA-capable GPU (optional, ONNX Runtime falls back to CPU)
git clone https://github.com/Kv-Logics/hypersphere-engine.git
cd hypersphere-enginecd backend
python ../scripts/download_models.pyThis downloads the three required model files into the models/ directory:
scrfd_2.5g_bnkps.onnxโ Face detectorw600k_r50.onnxโ ArcFace recogniser2.7_80x80_MiniFASNetV2.pthโ Liveness detector
docker-compose up -d postgresSpins up pgvector/pgvector:pg16 on port 5432. The face_attendance database and all tables are provisioned automatically on first API startup.
cd backend
python -m venv venv && source venv/bin/activate
pip install -r requirements.txt
bash run.shAPI will be available at http://localhost:8000. The Swagger docs are at http://localhost:8000/api/v1/openapi.json.
cd nextjs-frontend
npm install
npm run devDashboard available at http://localhost:3000.
docker-compose up --buildStarts both the PostgreSQL database and the API server in containers. Connect the frontend to http://localhost:8000.
All endpoints are prefixed with /api/v1.
| Method | Endpoint | Description |
|---|---|---|
POST |
/register |
Enroll a new face. Accepts multipart/form-data with faculty_id, name, image. |
POST |
/verify |
Verify identity. Accepts faculty_id + image. Performs 1:1 verification. |
GET |
/faculty |
List all enrolled faculty with metadata. |
GET |
/attendance |
Retrieve attendance logs with optional date/user filters. |
DELETE |
/faculty/{id} |
Remove a faculty member and their embeddings. |
GET |
/health |
System health check (DB connectivity, model status). |
{
"verified": true,
"faculty_id": "KV001",
"name": "Kv Logics",
"score": 0.847,
"liveness": true,
"liveness_score": 0.923,
"quality_passed": true,
"location": {
"insideCampus": true,
"buildingName": "Central Library"
}
}The system shifted from open-set identification (who is this?) to closed-set verification (is this person who they claim to be?). This is the standard production pattern for authenticated portals:
- A user logs in to the dashboard โ their
faculty_idis now known - The
/verifyendpoint restricts the vector search to only that identity's stored embeddings - This eliminates cross-identity false accepts entirely, regardless of threshold
| Version | MATCH_THRESHOLD |
Behaviour |
|---|---|---|
| v1.0 | 0.45 |
Too permissive โ Person A's embedding matched Person B at ~0.48 |
| v1.1 | 0.55 |
Better, occasional boundary cases |
| v2.0 (current) | 0.60 |
Strict โ genuine match scores typically >0.75, impostors typically <0.50 |
Campus spatial data is extracted from OpenStreetMap via the Overpass API.
| File | Description |
|---|---|
amrita_buildings.geojson |
103 building polygons |
amrita_attendance_polygons.json |
PiP-optimised format {building_id, building_name, polygon, centroid} |
amrita_campus_boundary.geojson |
Outer campus perimeter |
amrita_raw_osm.json |
Raw Overpass API response |
Coverage: 32 of 103 buildings are named in OSM (Central Library, Academic Block 2 & 3, Gargi/Vasishta Bhavanam hostels, Fabrication Workshop, etc.). The remaining 71 are tagged Building_<OSM_ID> for on-site naming.
To re-extract or refresh the campus data:
python scripts/extract_amrita.py- No raw images stored โ Only 512-D float embeddings are persisted. Original frames are discarded immediately after inference.
- Liveness mandatory โ Every verification attempt is blocked if MiniFASNetV2 flags the presentation as non-live.
- Accuracy filter on GPS โ Coordinates with >100m accuracy radius are rejected to prevent IP-based location spoofing.
- 1:1 scope binding โ Vector search is hard-scoped to the authenticated user's identity.
| Layer | Technology |
|---|---|
| ML Models | SCRFD (ONNX), ArcFace w600k_r50 (ONNX), MiniFASNetV2 (PyTorch) |
| Face Processing | MediaPipe, OpenCV, ONNX Runtime |
| Backend | FastAPI, Uvicorn, Python 3.10+ |
| Vector DB | PostgreSQL 16 + pgvector, FAISS (fallback) |
| ORM / Async | SQLAlchemy (async), databases, asyncpg |
| Frontend | Next.js 15, TypeScript, React 19 |
| Map Engine | Leaflet.js 1.9.4, Overpass API, Nominatim |
| Deployment | Docker, Docker Compose, Vercel (frontend), ngrok (dev) |
| Repo | Purpose |
|---|---|
| amrita-geofence-tester | Standalone deployment of the Amrita geofencing map for HTTPS GPS testing |
Research project developed under NITT-CDI / Amrita Vishwa Vidyapeetham collaboration.
Campus geospatial data ยฉ OpenStreetMap contributors โ ODbL License.