Get in touch
or send us a question?

Age and gender estimation technology


This document is describe about age and gender estimation technology based on Convolutional Neural Network and TensorFlow. This is a TensorFlow implement of face age and gender estimation which first using dlib to detect and align faces in the picture and then using a deep CNN to estimate age and gender.As you can see below,this project can estimate more than one face in a picture at one time.



How to build Age and gender estimation sample

So that you can better understand this technology, you should read ahead about face-recognition-technology.

Project dependencies

  • tensorflow==1.4
  • dlib==19.7.99
  • cv2
  • matplotlib==2.1.0
  • imutils==0.4.3
  • numpy==1.13.3
  • pandas==0.20.3

How to Use

1. Make tfrecords

In order to train your own models,you should first download imdb or wiki dataset,and then extract it under data path,after that,images path should look like


Then you can run

python --imdb --nworks 8


to convert images to tfrecords.–imdb means using imdb dataset,–nworks 8 means using 8 cpu cores to convert the dataset parallelly.Because we will first detect and align faces in the pictures,which is a time consuming step,so we recommend to use as many cores as possible.Intel E5-2667 v4 and with 32 cores need approximately 50 minutes.

2. Train model

Once you have converted images to tfrecords,you should have the following path:


At present,our deep CNN uses FaceNet architecture,which based on inception-resnet-v1 to extract features.To speed up training,we use the pretrained model’s weight from this project and have converted the weight to adapt our model,you can download this converted pretrained facenet weight checkpoint from here or here.Extract it to path models.



NOTE: This step is optional,you can also train your model from scratch. To start training,run

python --lr 1e-3 --weight_decay 1e-5 --epoch 6 --batch_size 128 --keep_prob 0.8 --cuda

NOTE: Using the flag –cuda will train the model with GPU.

Using tensorboard to visualize learning

tensorboard --logdir=./train_log

train log

3. Test model

You can test all your trained models on testset through

python --images "./data/test" --model_path "./models" --batch_size 128 --choose_best --cuda

Flag –cuda means using GPU when testing.–choose_best means testing all trained models and return the best one.If you just want to test the latest saved model,without this flag.

python --images "./data/test" --model_path "./models" --batch_size 128 --cuda

4. One picture demo

If you just want to test the model on your own picture,run

python --I "./demo/demo.jpg" --M "./models/" --font_scale 1 --thickness 1

Flag –I tells where your picture is.If the text label too small or too large on the picture,you can use a different –font_scale 1and –thickness 1 to adjust the text size and thickness. We also provide a pretrained model,you can download from here or here and extract it to models path.

Picture from web cam

web cam

First download the pretrained model from here or here and extract to models path. In order to get pictures from web cam, you may need to uninstall your cv2 and install it from source if have problems when running the below command:


Document refer

link source code:

Would you like to work with us in NeosCorp, please contact us here!

Notify of
Inline Feedbacks
View all comments