This repository contains the files for the app that implements the model.
This program has a hard time recognizing faces with a darker skin tone. Especially with the haar_cascade classifier. With my face there are false positives with an example being under here. People with lighter skin tones wont have a problem with their face being detected by the haar_cascadeclassifier then getting their facial image through the model.
The .tflite model does not work currently with this build. Reason being is the different input tensors that were created due to the way the model is structured when being converted to .tflite format. The tensorflow model can be run on the Pi the matter being that the Pi that can run it is only the Raspberry Pi Model 4B with RAM being 4 or 8GB.
Sadly the Raspberry Pi Model 3B doesn't have the capability of running the model. Even when the model is being run with the .tflite model without the input image being run through the verify function, the delay between actions on camera in real world is about 5 seconds. With major lag being detected throughout the program being run.
Correction the .tflite model now works on the raspberry pi model 3B. There was a parameter error in the interpreter.set_tensor()
line. Previously I did interpreter.set_tensor(input_details[0]['index'],np.expand_dims([input_img, validation_img], axis = 0).astype(np.float32)
. This outputted the error ValueError: cannot set tensor: Dimension mismatch. Got 5 instead of 4 for dimension 1 of input 0.
Im going to conclude that the reason for this error was due to both images being recognized as tensors even if i used the list() within the line as well. This error was corrected by doing input_img = np.expand_dims(input_img, axis = 0)
then the next line interpreter.set_tensor(input_details[0]['index'], input_img)
with this the program worked just as intended.
The specific error that will happen is with the ValueError: cannot set tensor: Dimension mismatch. Got 200 instead of 100 for dimension 1 of input 0
. This line is alluding to the input details tensor shape of [1, 100, 100, 3]
. Through different techniques of concatenating the input_shape as well as the input_details, more issues started to pop up. The .tflite runtime is especially difficult for custom models. It is recommended when using .tflite to have a relatively simple custom model or use one of the pre-trained models being offered by Tensorflow.
Siamese Neural Network and Training for the Smart Home Security with Facial Recognition using Raspberry Pi
This github repo is for the implementation of the model from the RealProjectPi-Files directory. When the face is detected the program sends a notification with details including the detection of a face as well as if the face was recognized or not.
This section provides instructions on how to use the code in this repository:
- Clone the repository:
- Change the Sender email to one that you have created.
- The SMTP api allows the program to control the email to send emails.
- Make sure to turn on 2-step-verification in the settings of your gmail.
- Scroll down to App passwords
- Then create a new app password. That app password will be the key you want to use for the
sender_app_password
inAlphaPi.py
.
- For the recipient email change it to the one you want the notifications to be sent to.
- In the
app_data
folder, add images of people you want to be verified into theverify_image
folder. - Make sure that the
haarcascade_frontalface_default.xml
file is in the folder. - Also confirm that the new model you have from siamesemodel is converted into
.tflite
format. - Run the
AlphaPi.py
script.
This section describes how to contribut to the project.
Because of this project being a Senior Capstone Project, please send me an email if you would like to continue working on this.
This section describes the license for the code in this repository. (Replace LICENSE.md
with the appropriate license file for your project.)
This project is licensed under the terms of the MIT license.
Below are two screenshots of emails sent from the system.