Welcome! This project is a complete, beginner-friendly facial recognition system built with Python, TensorFlow, and Kivy — and even integrates with Home Assistant to trigger automations when a specific person is detected.
I forked and improved this from the original by @nicknochnack. The original repo was great — but some things were outdated or missing. I fixed bugs, made it easier to run, and documented everything for you! 🎯
- Detects if a specific person appears on camera
- Compares the face using a trained Siamese neural network
- Triggers Home Assistant automations via webhook when verified (or unverified)
- Can also receive external commands to scan using a simple
curlcommand
- Anaconda (for managing environments and launching Jupyter)
- Git (to clone the project)
- Python 3.7 or higher (tested with Python 3.9.13)
- Optional: CUDA & cuDNN for GPU acceleration (much faster training!)
Download: https://www.anaconda.com/download/success
We use Anaconda to manage dependencies and avoid conflicts.
Once installed, open Anaconda Prompt and check:
conda --version
python --versionInstall Git if not already:
winget install --id Git.Git -e --source wingetClone this repository:
cd C:
git clone https://github.com/Mhikmat/FaceRecognition.gitcd C:
python -m venv FaceRecognitionEnv
cd FaceRecognitionEnv
.\Scripts\ActivateInstall Jupyter and make the kernel:
pip install ipykernel jupyterlab
python -m ipykernel install --name=FaceRecognitionEnv
jupyter kernelspec listcd ..\FaceRecognition
jupyter labRun the notebook
updated_facial_verification.ipynb
PressShift + Enterto execute each cell.
- If the camera doesn’t work, edit the code to try a different device:
cv2.VideoCapture(0) ➝ cv2.VideoCapture(1)- Collect:
- ~300 anchor images (
akey) - ~300 positive images (
pkey)
- ~300 anchor images (
In the notebook, continue running until the model is saved (model.keras).
This is the file you'll later move into the app.
-
Place your trained
model.kerasfile inside theFaceIDApp/directory. -
In
faceid.py, modify the model loading line to use your custom layer:self.model = tf.keras.models.load_model('model.keras', custom_objects={'L1Dist': L1Dist})
-
Still in
faceid.py, update the webcam capture line according to your camera setup:cap = cv2.VideoCapture(0) # Change the index (e.g., 0, 1, 2) depending on your device
-
Inside
FaceIDApp/, make the following folder structure:FaceIDApp/ ├── model.keras ├── faceid.py └── application_data/ ├── input_image/ └── verification_images/ -
Add approximately 30 reference images (copied from your
anchor/orpositive/folders) intoapplication_data/verification_images/. -
The
input_image/folder will store the captured image that will be compared with all images inverification_images/.
When a new image is captured:
- It is saved into
input_image/. - The Siamese model compares it with each image in
verification_images/. - If the number of positive matches exceeds the number of non-matches, the user is considered verified.
Your faceid.py already has webhook logic:
# Verified
http://homeassistant.local:8123/api/webhook/faceid_verified
# Unverified
http://homeassistant.local:8123/api/webhook/faceid_unverifiedIn Home Assistant:
- Go to ⚙️ Settings → Automations → ➕ New Automation
- Choose “Webhook” as the trigger
- Use
faceid_verifiedorfaceid_unverifiedas the webhook ID - Set actions like turning on lights or sending a notification
You can also trigger the scan remotely from another device on the same network using a simple curl command.
Replace 192.168.216.11 with the local IP address of the machine running the app:
curl -X POST http://192.168.216.11:5000/webhook -H "Content-Type: application/json" -d "{\"status\": \"scan\"}"✅ Tip: To find your local IP address on Windows:
Open Command Prompt and type:
ipconfigThen look under your network adapter for:
IPv4 Address. . . . . . . . . . . : 192.168.xxx.xxxInside the FaceIDApp folder:
python faceid.py✅ Model training via Jupyter
✅ Live camera detection
✅ Verified = webhook trigger
✅ Unverified = webhook trigger
✅ External trigger via API
✅ Home Assistant integration
- More verification images = better accuracy
- Make sure lighting is consistent
- GPU will greatly reduce training time (install CUDA Toolkit)
You can find a full Batch Setup Script in the repo:
➡️ README_FaceRecognition_Setup.bat
Just run it and follow the prompts.
Forked from nicknochnack/FaceRecognition
Adapted and improved by @Mhikmat




