# Age and gender estimation based on Convolutional Neural Network and TensorFlow
---
**UPDATE: There are some compatibility issues under python3 reported by others, recommend using python2 or you should adjust some codes manually**
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.
![demo1](https://raw.githubusercontent.com/BoyuanJiang/Age-Gender-Estimate-TF/master/demo/demo1.jpg)
![demo2](https://raw.githubusercontent.com/BoyuanJiang/Age-Gender-Estimate-TF/master/demo/demo2.jpg)
## Dependencies
This project has following dependencies and tested under CentOS7 with Python2.7.14
- tensorflow==1.4
- dlib==19.7.99
- cv2
- matplotlib==2.1.0
- imutils==0.4.3
- numpy==1.13.3
- pandas==0.20.3
## Usage
### Make tfrecords
In order to train your own models,you should first download [imdb](https://data.vision.ee.ethz.ch/cvl/rrothe/imdb-wiki/static/imdb_crop.tar) or [wiki](https://data.vision.ee.ethz.ch/cvl/rrothe/imdb-wiki/static/wiki_crop.tar) dataset,and then extract it under **data** path,after that,images path should look like
> /path/to/project/data/imdb_crop/00/somepictures
/path/to/project/data/imdb_crop/01/somepictures
....
/path/to/project/data/imdb_crop/99/somepictures
Then you can run
```bash
python convert_to_records_multiCPU.py --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.
### Train model
Once you have converted images to tfrecords,you should have the following path:
> /path/to/project/data/train/train-000.tfrecords
......
/path/to/project/data/test/test-000.tfrecords
......
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](https://github.com/davidsandberg/facenet) and have converted the weight to adapt our model,you can download this converted pretrained facenet weight checkpoint from [here](https://mega.nz/#!4G4yxbAL!D9QG48yzCeFegCFhZfpCgOyLYbfDdU6lt2k2kK9n23g) or [here](https://pan.baidu.com/s/1dFewgqH).Extract it to path **models**.
> /path/to/project/models/checkpoint
/path/to/project/models/model.ckpt-0.data-00000-of-00001
/path/to/project/models/model.ckpt-0.index
/path/to/project/models/model.ckpt-0.meta
**NOTE:** This step is optional,you can also train your model from scratch.
To start training,run
```bash
python train.py --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](https://raw.githubusercontent.com/BoyuanJiang/Age-Gender-Estimate-TF/master/train_log/train_log.jpg)
### Test model
You can test all your trained models on testset through
```
python test.py --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 test.py --images "./data/test" --model_path "./models" --batch_size 128 --cuda
```
### One picture demo
If you just want to test the model on your own picture,run
```
python eval.py --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 1** and **--thickness 1** to adjust the text size and thickness.
We also provide a pretrained model,you can download from [here](https://mega.nz/#!BfglkI7A!YBvFyxgKhvUnnNRu9FL-ACjdo18SmOZ-YSz9QghQRzE) or [here](https://pan.baidu.com/s/1bpllJg7) and extract it to **models** path.
### Picture from web cam
![web cam](https://raw.githubusercontent.com/BoyuanJiang/Age-Gender-Estimate-TF/master/demo/demo.gif)
First download the pretrained model from [here](https://mega.nz/#!kaZkWDjb!xQvWi9B--FgyIPtIYfjzLDoJeh2PUBEZPotmzO9N6_M) or [here](https://pan.baidu.com/s/1kVd3TNx) 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](https://www.scivision.co/anaconda-python-opencv3/) if have problems when running the below command:
```bash
python demo.py
```
## TODO
- [x] First version of project
- [x] Code review and add some commits
- [x] Add a readme doc
- [x] Add a demo using pictures from web cam
## References and Acknowledgments
This project is a part of my class project of Machine Learning course at Zhejiang University,following papers and codes are referred:
1. Rothe R, Timofte R, Van Gool L. Dex: Deep expectation of apparent age from a single image[C]//Proceedings of the IEEE International Conference on Computer Vision Workshops. 2015: 10-15.
2. Rothe R, Timofte R, Van Gool L. Deep expectation of real and apparent age from a single image without facial landmarks[J]. International Journal of Computer Vision, 2016: 1-14.
3. [IMDB-WIKI – 500k+ face images with age and gender labels](https://data.vision.ee.ethz.ch/cvl/rrothe/imdb-wiki/)
4. [yu4u/age-gender-estimation](https://github.com/yu4u/age-gender-estimation)
5. [davidsandberg/facenet](https://github.com/davidsandberg/facenet)
6. [Face Alignment with OpenCV and Python](https://www.pyimagesearch.com/2017/05/22/face-alignment-with-opencv-and-python/)
没有合适的资源?快使用搜索试试~ 我知道了~
Python-TensorFlow实现的人脸性别年龄识别
共25个文件
py:12个
jpg:4个
ipynb:2个
3星 · 超过75%的资源 需积分: 18 127 下载量 24 浏览量
2019-08-11
05:52:06
上传
评论 22
收藏 70.58MB ZIP 举报
温馨提示
TensorFlow实现的人脸性别/年龄识别
资源推荐
资源详情
资源评论
收起资源包目录
Python-TensorFlow实现的人脸性别年龄识别.zip (25个子文件)
Age-Gender-Estimate-TF-master
saved_model.py 2KB
models
Put pretrained model here 0B
eval.py 5KB
inception_resnet_v1.py 13KB
inspect_checkpoint.py 5KB
shape_predictor_68_face_landmarks.dat 95.08MB
read_images.ipynb 46KB
utils.py 5KB
test.py 6KB
train.py 7KB
libboost_python.so.1.65.1 362KB
demo.py 5KB
convert_to_records.py 7KB
LICENSE 1KB
resnet_model.py 19KB
model_transfer.py 1KB
demo
demo2.jpg 29KB
demo1.jpg 57KB
demo.gif 1.07MB
demo.jpg 213KB
convert_to_records_multiCPU.py 10KB
inception_resnet_v1.pyc 9KB
README.md 6KB
train_log
train_log.jpg 105KB
print_parameter.ipynb 5KB
共 25 条
- 1
资源评论
- 破晓前的彷徨2019-09-26用着还不错 准确
- 冷色调的夏天2019-12-07这是python2.7的 没有3.7的么
weixin_39840387
- 粉丝: 784
- 资源: 3万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- PHP端通过modbus协议跟第三方设备进行数据通信
- navicat安装包亲测可用
- 算法部署-使用OpenVINO部署MobileStyleGAN轻量化高保真图像合成算法-项目源码-优质项目实战.zip
- 基于java实现远程采集华为逆变器使用modbus tcp协议进行通讯的设备数据
- Unity画面共享Spout插件
- 基于C++用modbus实现的工业设备的数据采集程序,支持Tcp、串口
- 完结12章AI Agent智能应用从0到1定制开发
- 15白落梅:你是锦瑟我为流年:三毛的万水千山-3491776.mobi
- Federated Learning-Aided Prognostics in the Shipping 4.0: Princi
- OFDM 的鲁棒频率和定时同步文献部分阅读笔记
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功