For creating a facial recognition model we need the facial landmarked data from the images . To get it , we need to manually label all the images using the labeltools , annotate the image with their coordiantes and then convert it to a csv file . Then we preprocess it to respective data file format like tfrecord etc. To make it easy for the AI Developers , I coded this module which can automatically detect , annotate , collect the coordinates , convert to csv and to tfrecord . And I added a feature to visulaize your detected face on the image according by their respective classes.
The code is tested and developed in ubuntu 18.04 and using pyton 3.6.But the code has the realiability to run on most of the configuration . If you face issues , do open up an issue for this repo .All the package dependencies are mentioned in requirements.txt.
- Preprocessing all the images to a standard size and format
- Loading the preprocessed image
- Detecting the Face in the image using MTCNN or Harr-Cascade Algorithm and removing bad images
- Getting the face coordinates
- Writing into csv
- Converting into tfrecord
- Exporting the images with the face bounding box for debuging
Core Functionality
main.py
- Parse the arguments , load the images , call the detect,cordinates,preprocess functionscoordinates.py
- Using MTCNN it detects the facial boundary coordinatescascade.py
- Using Harr-Cascade detects the facial boundary coordinatesgenerate_tfrecord.py
- Used to generate the tfrecord for the csvdataset_util
- some utility functions for generate_tfrecordcheck.py
- load the processed image and export the output with the bounding boxbounding.py
- draw the bounding box using opencvrequirements.txt
- contains all the packages and their versions
Note : The images should be in jpg format and each image of a class should have only one person image.
- Create a python virtual environment and pip install the requirements.txt
- Then prepare the images folder according to structure
- Create a empty output directory
- To detect the face using Facenet run
python main.py csv_name tfrecord_name facenet
.Example :python main.py train.csv train.record facenet
- To detect the face using Harr-Cascade run
python main.py csv_name tfrecord_name harr
. Example :python main.py train.csv train.record harr
- After code execution , you will get a csv and tfrecord file . To view the detection is perfect , go to the output directory you can view all the images with detection according to their respective class.
- Simple !
It automatically removes all the bad format images and multiple face images
- MTCNN : https://kpzhang93.github.io/MTCNN_face_detection_alignment/paper/spl.pdf
- Harr-Cascade : https://docs.opencv.org/3.3.0/d7/d8b/tutorial_py_face_detection.html
- To know more about tfrecord : https://www.skcript.com/svr/why-every-tensorflow-developer-should-know-about-tfrecord/
Copyright © 2021 Robin Reni. All rights reserved