This project is a facial recognition system designed to trigger actions based on the presence or absence of a specific face. It uses InsightFace for accurate, GPU-accelerated face recognition. This solution is made for personal use cases such as automatically locking the system, turning off the screen or unmounting VeraCrypt and hibernating your PC (therefor locking your drives) when your face is no longer detected.
- Fast face recognition using InsightFace (
buffalo_lmodel) - Real-time webcam detection with optional GUI
- Configurable via
.cfgfiles - Multiple operating modes:
- Debug mode
- Monitor sleep control
- VeraCrypt unmount + hibernation
- Custom face recording tool
- Failsafe exit (
CTRL+M) - Works with GPU acceleration (if set up properly)
- Python 3.8+
- Windows 10/11
- NVIDIA GPU (optional but recommended for real-time performance)
- VeraCrypt (optional, only needed for VeraCrypt mode)
-
Clone the repository or download the files.
-
Install dependencies:
You can use the
.batinstaller provided:install_dependencies.batOr manually install:
pip install opencv-python insightface numpy keyboard colorama
-
Download ONNX model weights:
InsightFace will automatically download the required ONNX models (
buffalo_l) on first run. If needed, you can also download them manually from the InsightFace model zoo.
This project is GPU-enabled via ONNX Runtime. To ensure GPU support:
-
Install the correct version of
onnxruntime-gpu:pip uninstall onnxruntime pip install onnxruntime-gpu
-
Make sure you have the latest NVIDIA drivers and CUDA installed. CUDA 11.x or 12.x is typically required, depending on your GPU.
-
The face analysis module is initialized with:
FaceAnalysis(providers=["CUDAExecutionProvider", "CPUExecutionProvider"])
You can verify GPU usage with a monitoring tool like
nvidia-smi.
To use GPU acceleration, ONNX Runtime requires access to the cuDNN libraries. Specifically, the onnxruntime-gpu package looks for DLL files such as cudnn64_*.dll.
You must:
- Download cuDNN that matches your installed CUDA version (e.g. CUDA 12.2 → cuDNN 9.x).
- Extract the downloaded files.
- Ensure that the directory containing
cudnn64_*.dllis either:- Added to your system
PATH, or - Placed in the same directory as your Python interpreter or the
onnxruntime_providers_cuda.dll.
- Added to your system
If cudnn64_9.dll is missing, you will see an error like:
error loading onnxruntime_providers_cuda.dll which depends on "cudnn64_9.dll" which is missing.
Make sure to verify compatibility between your CUDA, cuDNN, and onnxruntime-gpu versions.
Run the face recording utility to collect reference embeddings:
record_reference.batThis launches the camera, records for the configured number of seconds, and saves your face embeddings in reference_embeddings.pkl.
After creating your reference profile, start the detection script:
run_detector.batThe script loads the webcam and checks for your face. If not seen for a configurable timeout, it performs an action (monitor off, hibernate, etc.) depending on mode.
Both scripts use .cfg files to define runtime parameters (e.g., camera index, duration, thresholds, GUI mode). You can modify:
main_config.cfg— used by the main face detectorrecorder_config.cfg— used by the face recorder
- VeraCrypt must be available in your system
PATHif you want to use VeraCrypt mode. - Use
CTRL+Mat any time to forcefully terminate the detector script. - Monitor on/off is managed using PowerShell via WinAPI (no third-party tools needed).
MIT License