My implementation for face recognition using FaceNet model and Triplet Loss. I like to implement different deep learning models architectures. I also like to read about applications and implementations of deep learning models. I have typed this code in my free time as a self learning exercise. So, if you run into some performane issue, i am not an expert , i won't be able to help you. I also don't have hardware to extensively test a heavy model like FaceNet. So, hyperparameters are not tuned at all. Only thing I can assure you is that this implementation works.
Create a dataset of faces for each person and arrange them in below order.
root folder
│
└───Person 1
│ │───IMG1
│ │───IMG2
│ │ ....
└───Person 2
| │───IMG1
| │───IMG2
| | ....
Use align_dataset_mtcnn.py
to prepare our dataset for training. Run the following command:
python align_dataset_mtcnn.py ./YOUR_DIRECTIORY_CONTAINING_DATA ./cropped
example:
Run train_triplet.py
to train the model. Make changes (if you want) in parameters.py
to adjust training parameters.
Run webcamFaceRecoMulti.py
to recognize faces in real time. Note- Our dataset must have some images for this script to work.
It is not state of the art technique. So, dont't expect much from it.
Model is trained using triplet loss. According to experiments it is recommended to chose positive
, negative
and anchor
images carefully/manually for better results. Here I used a generator which selects images for positive
, negative
and anchor
randomly (I'm Lazy af). To know more about this I recommend you to watch this video.