- A real-time age and gender recognition of face model with only 1mb, 0.531×10^6 parameters and 0.074 GFLOPs.
- Using OpenVINO to accelerate the speed of real-time recognition on intel D415.
- The backbone of model structure is MobileFaceNet.
- CelebA, AFAD, MegaAge-Asian and UTKFace dataset is used for model training.
Code Author: Vaan Lin
Last update: 2020/07/22
Please install Anaconda(Python 3.7 64-Bit) first.
- CUDA 10.1
- cudnn 7.6.4
- Tensorflow-GPU 2.2.0
- Keras 2.3.1
- cvlib 0.2.2
- numpy 1.17.4
- pyrealsense2 2.31.0.1235
- matplotlib 3.3.3
- opencv-python 4.5.1.48
You can install the package of above at once by using command:
pip install -r requirements.txt
- OpenVINO the lastest version
- Anaconda
- MobileFaceNet (https://arxiv.org/ftp/arxiv/papers/1804/1804.07573.pdf)
- cvlib (https://github.com/arunponnusamy/cvlib)
- This part describes the roughly process of TFrecords generation, training and model convertion.
- Dataset --> ./TFRecords_Create/gen_TFRecords.py --> [Asian and UTK].tfrecords
- [Asian and UTK].tfrecords, MFN_62_075_gender_pre-trained.h5 --> ./Training/MFN_Train.py
- ./Training/Results/Keras_h5/MFN.h5 --> ./Tools_Convert/Keras2pb.py --> MFN.pb
- MFN.pb --> Convert pb to IR --> MFN.bin, MFN.mapping and MFN.xml
If you wanna use your datasets to train on my model, please notice the following:
- This model is for age and gender recognition, so make sure your dataset can be labeled like:
- When you have already prepared your label.csv, put your images at
./FaceAgeGenderRecognition/Datasets
and you can generate TFRecors by executing gen_TFRecords.py
- The results of TFRecords will save at
./FaceAgeGenderRecognition/TFRecords_Create/TFRecords/train(or test)
- If you wanna use the model to inference your images
- Put your images in
./FaceAgeGenderRecognition/Demo/Image/Demo_Image
- Double click run_Image_Demo.bat
- The results will be saved in
./FaceAgeGenderRecognition/Demo/Image/Results
Insure you have already installed OpenVINO.
- If you wanna use the model to achieve the real-time recognition on intel D415
- Double click run_Webcam_Demo.bat
- If you want to re-train the model of using your dataset of TFRecords
- Double click run_MFN_Train.bat
Insure you have already installed OpenVINO.
- If you wanna use the model to inference your images
- Activate your Anaconda environment
- Put your images in
./FaceAgeGenderRecognition/Demo/Image/Demo_Image
- Executed by python:
[OpenVINO]
python ./Demo/Image/Image_Test.py --m OpenVINO --i ./Demo/Image/Demo_Image --o ./Demo/Image/Results/ --x ./Training/Results/Openvino_IR/MFN.xml --b ./Training/Results/Openvino_IR/MFN.bin
[Keras]
python ./Demo/Image/Image_Test.py --m Keras --i ./Demo/Image/Demo_Image --o ./Demo/Image/Results/ --h [Path of .h5 file]
--m means what model type you wanna use
--x means path of OpenVINO .xml file
--b means path of OpenVINO .bin file
--i means path of input images
--o means path of output images
- If you wanna use the model to achieve the real-time recognition on intel D415
- Activate your Anaconda environment
- Executed by python:
python ./Demo/RealTime/Webcam.py --x ./Training/Results/Openvino_IR/MFN.xml --b ./Training/Results/Openvino_IR/MFN.bin --r 1280
--x means path of OpenVINO .xml file
--b means path of OpenVINO .bin file
--r means the resolution of D415(include 1920(1920x1080), 1280(1280x720) and 960(960x540))
- If you want to create the tfrecords by yourself
- Activate your Anaconda environment
- Executed by python(Asian):
python ./TFRecords_Create/gen_TFRecords.py --i ./FaceAgeGenderRecognition/Datasets/Asian_FaceData/ --c ./TFRecords_Create/Asian_FaceData.csv --t ./TFRecords_Create/TFRecords --n Asian
--i means the path of dataset
--c means the path of csv file
--t means the path of output tfrecords
--n means the name of output tfrecords
- If you want to re-train the model of using your dataset of TFRecords
- Activate your Anaconda environment
- cd ./FaceAgeGenderRecognition/Training
- Executed by python:
python MFN_Train.py --tn ./FaceAgeGenderRecognition/Outputs/TFRecords/test/ --m .././Model/Backbone/MFN_62_075_gender_pre-trained.h5 --p Y
--tn means path of training tfrecords
--ts means path of testing tfrecords
--m means the path of model
--p means If use pre-trained model or not
All of training details you can check the document named FaceAgeGenderRecognition.pdf.
- Gender
- Age
Results of (a) OpenVINO, (b) InsightFace and (c) Our Model age estimation. X-axis means range of age from 18 to 65, and y-axis means the mean absolute error (MAE) of model estimation in every age.