Computer vision · 2025
Face recognition attendance
Attendance from ordinary cameras with a liveness check, SCRFD detection and ArcFace recognition in ONNX, served by FastAPI over HTTP and WebSocket to a Next.js front end.
+5 % accuracy vs YOLOv5 on real cameras, 10 % less compute
- Problem
- Taking attendance from a camera fails on real footage: small faces, motion blur, mixed lighting. A single detector-classifier trained end to end (the YOLOv5 baseline) could not keep up as the number of people grew.
- Approach
- A liveness check first, then two decoupled stages: SCRFD for face detection and ArcFace (ResNet-50, Additive Angular Margin Loss) for identity embeddings, matched against enrolled faces with a similarity threshold of 0.4. Both models run in ONNX behind FastAPI, over a POST endpoint and a WebSocket for live frames, with a Next.js front end that exports attendance to CSV.
- Result
- 5 % higher accuracy than the YOLOv5 baseline on real-world cameras. Decoupling detection from recognition cut compute cost by 10 % while raising overall accuracy by 12 %, because each stage could be sized and retrained independently.
Problem
[Who used it, how many people, which cameras. Describe the failure modes of the baseline you replaced: for example new enrolments forcing a retrain of the whole model, or small faces at the back of the room.]
Architecture
Browser capture. The Next.js front end grabs webcam frames and sends them as JPEG, either one shot to POST /api/face-recognition or as a stream of binary frames over WebSocket /ws/face-recognition. The server decodes them with OpenCV; nothing is written to disk.
Liveness check. A small Keras classifier (liveness_detect/FDM.py, model_1.h5) runs before detection; a frame judged "Fake" is rejected with "Liveness check failed", so a photo held up to the camera does not get marked present.
SCRFD detector. SCRFD 10G (det_10g.onnx): a lightweight face detector with 5 landmarks, chosen over YOLOv5 for small faces and speed.
Alignment. Faces warped to 112 × 112 by the landmarks so the embedding network always sees the same geometry.
ArcFace ResNet-50. ArcFace w600k_r50.onnx: identity embedding trained with Additive Angular Margin Loss, which pushes classes apart on the hypersphere and makes similarity matching reliable.
Matching + enrolment. At start-up the server embeds every image in the faces/ folder into an in-memory gallery. A frame is matched to the most similar enrolled face if the similarity exceeds 0.4, otherwise it is "Unknown". Adding a person is one photo, no retraining.
Next.js front end. Next.js 15 + React 19 + Tailwind, deployed on Vercel. Shows boxes, names and confidence per frame and exports the attendance list to CSV (papaparse + file-saver).
Results
| Pipeline | Accuracy on real cameras | Compute |
|---|---|---|
| YOLOv5 single-stage baseline | reference | reference |
| SCRFD + ArcFace, decoupled | +5 % vs YOLOv5; +12 % overall after decoupling | −10 % |
[Replace “reference” with the absolute numbers and say how accuracy was measured: number of sessions, number of identities, threshold used.]
Challenges and lessons
- Thresholds matter more than the model. [Note how you chose the cosine threshold and what false-accept / false-reject trade-off you landed on.]
- Enrolment quality. [What enrolment protocol you used: how many photos, which angles, how you rejected bad ones.]
- ONNX export. [Any operator or precision issue when exporting ArcFace, and the latency you measured on CPU vs GPU.]
Links
- Backend (FastAPI, SCRFD + ArcFace, liveness): github.com/x23d8/attendance-backend
- Front end (Next.js): github.com/x23d8/attendance-frontend
- Live front end: attendance-frontend-sandy.vercel.app (needs the backend running to recognise faces)
The demo is hosted at attendance-frontend-sandy.vercel.app. Nothing loads until you ask.