GITHUB:https://github.com//BoyuanJiang/Age-Gender-Estimate-TF
clone 代码。
下载数据集 到 ~/data
wget https://data.vision.ee.ethz.ch/cvl/rrothe/imdb-wiki/static/imdb_crop.tar
加压缩
tar -xvf imdb_crop.tar
数据集预处理
python convert_to_records_multiCPU.py --imdb --nworks 8
训练的时候发现输出的文件为空。
try 了一下
example = tf.train.Example(features=tf.train.Features(feature={
# 'height': _int64_feature(rows),
# 'width': _int64_feature(cols),
# 'depth': _int64_feature(depth),
'age': _int64_feature(int(ages[index])),
'gender': _int64_feature(int(genders[index])),
'image_raw': _bytes_feature(image_raw),
'file_name': _bytes_feature(str(file_name[index][0]))}))
报错
’40/nm1102140_rm3713850624_1974-7-29_2013.jpg’ has type <class ‘str’>, but expected one of: ((<class ‘bytes’>,),)
去掉
'file_name': _bytes_feature(str(file_name[index][0]))
程序可以正常跑了
训练的时候报错
Invalid argument: Name: <unknown>, Feature: file_name (data type: st
ring) is required but could not be found.
修改 file_name 行如下
'file_name': _bytes_feature(bytes(file_name[index][0],'utf-8'))}))
重新生成。。。
或者换成
python convert_to_records.py –imdb
就好了。
下载models:https://pan.baidu.com/s/1dFewgqH
训练好的model
https://pan.baidu.com/s/1bpllJg7
Train
python3 train.py --lr 1e-3 --weight_decay 1e-5 --epoch 6 --batch_size 128 --keep_prob 0.8 --cuda
Test 选出最好的模型
python3 test.py --images "./data/test" --model_path "./models" --batch_size 128 --choose_best --cuda
Age_MAE:7.07,Gender_Acc:80.92%,Age_model:./models/model.ckpt-12001,Gender_model:./models/model.ckpt-9001
用自己的图片测试
python3 eval.py --I "./demo/demo.jpg" --M "./models/" --font_scale 1 --thickness 1
另一个Keras 的实现: Keras 实现的性别年龄检测