# FaceAttend for Linux FaceAttend is a face-recognition attendance system for RTSP cameras. It records check-in and check-out automatically when people walk past a camera. - Runs on Linux x86_64 (Ubuntu / Debian tested) with a normal CPU; no graphics card needed. - Python 3.9.9 with PyQt5. - Five face-recognition models to choose from, each as ONNX or the PyTorch model. ## Install 1. Download this repository from https://huggingface.co/mchuca/AttendanceSystem. You need these three folders, in the same layout: ``` AttendanceSystem(linux)/ this project packages/linux/ Python 3.9.9 source and all Python packages (CPU builds) models/ face recognition models ``` 2. Run `./setup.sh` inside `AttendanceSystem(linux)`. It needs no internet when `packages/linux` is present. It does four things: - uses Python 3.9.9 from `~/.local/opt/python-3.9.9` or the `PATH`; otherwise it builds 3.9.9 from the bundled source into `~/.local/opt/python-3.9.9`. The app runs on exactly this version, so another Python 3.9.x is not used; - creates `.venv`; - installs the Python packages from `packages/linux`; - copies the models into `models/`. Building Python needs these system libraries (Debian/Ubuntu): ```bash sudo apt install build-essential libssl-dev zlib1g-dev libffi-dev libsqlite3-dev libbz2-dev liblzma-dev libreadline-dev uuid-dev ``` 3. Start the app with `./run.sh`. If the window does not open, install the Qt libraries: `sudo apt install libxcb-xinerama0 libxkbcommon-x11-0 libxcb-cursor0`. ## First steps 1. **Cameras** → *Add camera* → enter the RTSP address and pick a role, then press *Test connection*. - Hikvision: `rtsp://user:pass@192.168.1.64:554/Streaming/Channels/101` - Dahua: `rtsp://user:pass@IP:554/cam/realmonitor?channel=1&subtype=0` - A USB webcam: `0`. A video file: its path. 2. **Employees** → *Add employee* → *Enroll (camera)* (the person turns their head slowly) or *Enroll (photos)*. 3. **Live monitor** → *Start monitoring*. 4. **Attendance** → daily records with absent people, the recognition log, the monthly summary, manual corrections, and CSV / Excel export. | Camera role | Behaviour | |---|---| | Entry | the first sighting of the day is the check-in | | Exit | every sighting updates the check-out; the last one of the day counts | | Both | the first sighting is the check-in; a sighting at least *Check-out min gap* later is the check-out | A check-in after *Work starts* plus the *Late after grace* minutes is marked **Late**. ## Recognition models (Models page) | Model | Accuracy | Speed on CPU | Size | License | |---|---|---|---|---| | FaceNet · VGGFace2 (default) | ★★★★☆ | ★★★☆☆ | 90 MB | MIT | | FaceNet · CASIA-WebFace | ★★★☆☆ | ★★★☆☆ | 90 MB | MIT | | ArcFace · ResNet-50 (InsightFace) | ★★★★★ | ★☆☆☆☆ | 166 MB | non-commercial research only | | ArcFace · MobileFaceNet (InsightFace) | ★★★★☆ | ★★★★★ | 13 MB | non-commercial research only | | SFace (OpenCV Zoo) | ★★★☆☆ | ★★★★☆ | 37 MB | Apache-2.0 | - **Formats:** each model can run with **ONNX Runtime** (faster on CPU) or as the **PyTorch `.pt`** model. - For FaceNet the `.pt` file is the original release, and the ONNX version is converted from it. - ArcFace and SFace were released as ONNX. Their `.pt` files are TorchScript conversions. - Both formats give the same results. - **Switching models:** enrolled faces are converted automatically, so nobody has to enroll again. - **Missing files:** a model that isn't on the PC is downloaded from its official source when you select it, and its checksum is checked. `./prepare_models.sh` fetches every model in both formats in advance. - **Commercial use:** the ArcFace models are licensed for non-commercial research only. For commercial use, choose FaceNet or SFace. - **Thresholds:** each model has its own match threshold, track gate and same-person similarity, under Settings → Recognition. ## Tuning | Setting | Default | Notes | |---|---|---| | Match threshold | per model | Raise it if strangers get recognized; lower it if staff stay "Unknown". | | Votes needed to confirm | 3 of 7 | More votes means fewer false marks but slightly slower confirmation. | | Recognition passes / s / camera | 5 | On a typical CPU, one camera gets about 2–5 passes per second. ArcFace MobileFaceNet is the lightest model for several cameras. | | Detection image max side | 960 px | Lower it for speed, raise it when faces are small in the picture. | | CPU threads | 0 (auto) | Limit it if other programs need CPU time. | ## Troubleshooting - **The app doesn't start:** run `./run.sh` in a terminal and read the message. Also check `logs/app.log`. - **"Could not load the Qt platform plugin xcb":** install the Qt libraries listed under Install. - **A camera doesn't connect:** check the address in VLC first. Settings → RTSP transport can be switched to `udp`. - **A webcam is not found:** try `1`, `2`... instead of `0`. Your user also needs to be in the `video` group. ## Files | Path | What it is | |---|---| | `main.py` | start-up: logging, login, window | | `core.py` | everything except the GUI: settings, SQLite database, RTSP capture, face detection (MTCNN), the recognition models (ONNX / PyTorch), matching, tracking, attendance rules, reports | | `gui.py` | the PyQt5 window and its pages | | `convert.py` | model conversion: FaceNet `.pt` → ONNX and ONNX → TorchScript `.pt`, each checked against its source | | `setup.sh`, `run.sh`, `prepare_models.sh` | install and start | | `tests/` | unit tests (`.venv/bin/python -m pytest tests`) | The app creates these at runtime: - `config/settings.json`; - `data/attendance.db`; - `data/snapshots/`, `data/unknown/` and `data/faces/` for face pictures; - `logs/app.log`. Face pictures and face embeddings are personal (biometric) data. Restrict access to the `data` folder, and inform the people concerned and ask for their consent as your local law requires.