A Kivy desktop app that does face verification from a webcam using a Siamese neural network. It shows a live camera feed and, when you press Verify, compares the current frame against a set of stored reference images.
The model is trained in mhussainahmad/face_detection. This repository contains the app and a copy of the training notebook.
faceid.pybuilds a Kivy layout with three parts: a webcam image widget, a Verify button and a status label. It updates the camera image about 33 times a second, using a 250x250 crop of each OpenCV frame.- On Verify:
- The current crop is saved to
application_data/input_image/input_image.jpg. - The crop is resized to 100x100 and scaled to [0, 1].
- The model scores it against every image in
application_data/verification_images/.
- The current crop is saved to
- A comparison counts as a match when its score is above
detection_threshold = 0.99. - The label shows Verified when the share of matches is above
verification_threshold = 0.8. layers.pydefines the customL1Distlayer (absolute difference of the two embeddings), which is needed to load the saved Keras model.
faceid.py Kivy app (camera feed, preprocessing, verification)
layers.py Custom L1Dist Keras layer
face_recognition.ipynb Data collection and Siamese model training (local version of the face_detection notebook)
TODO.md Build checklist used while writing the app
These files are gitignored, so you need to provide them before running:
siamesemodel.h5 # trained model, from the face_detection notebook
application_data/
input_image/ # the app writes the captured frame here
verification_images/ # reference photos of the person to verify
Then:
pip install kivy opencv-python tensorflow numpy
python faceid.py # run from the repository rootNo requirements file is included. The training notebook was run with TensorFlow 2.4.1.
faceid.py opens camera index 4 (cv2.VideoCapture(4)). On most machines the built-in webcam is index 0, so change that line if the feed is blank.
Python, Kivy, OpenCV, TensorFlow/Keras.
MIT. See LICENSE.