This repository is used for finding and predicting from an image one or multiple human's gender and age(confidence scores provided for both age and gender). 94% acc for gender and MAE of 4.2 for age can be achieved after just 32 epochs of training.
- python3, pytorch
pip3 install --upgrade opencv-python, dlib, imutils, skimage
- Download FaceAligner and save
shape_predictor_68_face_landmarks.dat
inmodels/
- Download FaceDetector and save
mmod_human_face_detector.dat
inmodels/
- Put your image in pics/ (see config.ini for naming details)
- Run preprocessing steps in
preprocess.py
- Run
train.py
- train the model using
python train.py
, weight will be stored inmodels/
- put your test image in
pics/val/
- run
python evaluate.py
call eval_live()
function in evaluate.py
- Using cleaned IMDB-WIKI dataset[1] for training (IMDB-WIKI dataset contains 50%+ mislabeled images[2]).
- Using FG-NET dataset[3] for testing.
- Train a model based on ResNet-18,
- the output is 2 neuron represents probs of male&female plus 100 neurons represents probs of being age 0-99.
- auto detect if use GPU or even multiple GPUs for training.
- auto reduce learning rate when we have no loss reduce on val dataset for >N epochs.
- auto freeze CNN layers and train only last FCN layers when first epoch.
- auto load and save weights, log training loss and metadatas after each epoch.
- more detains can be found on src file
train.py
and configuration fileconfig.ini
- detect and align faces using
dlib
. - predict age, gender and confidence scores(probability of each gender and variance of age).
[1] Rothe R, Timofte R, Van Gool L. Deep Expectation of Real and Apparent Age from a Single Image Without Facial Landmarks [J/OL]. International Journal of Computer Vision. 126 (2). 2018, Apr: 144–157.
[2] Antipov G, Baccouche M, Berrani S-A et al. Effective training of convolutional neural networks for face-based gender and age prediction [J/OL]. Pattern Recognition. 72. 2017, December: 15–26.
[3] Panis G, Lanitis A, Tsapatsoulis N et al. Overview of research on facial ageing using the FG-NET ageing database [J]. IET Biometrics. 5 (2). 2016: 37–46.
Feel free to mail [email protected] for any quetsions or bug report about this repo :)