一、相关代码及训练好的模型
eveningglow/age-and-gender-classification: Age and Gender Classification using Convolutional Neural Network https://github.com/eveningglow/age-and-gender-classification
二、部署
1、打开Caffe.sln工程,编译方法见:https://www.cnblogs.com/smbx-ztbz/p/9380273.html
2、将相关源文件及模型拷贝至如下目录:
3、在examples中新建工程,且将对应源码添加进来
4、属性设置:
(1)进入“C/C++”,选中“常规”,“附加包含目录”输入如下:
D:\Projects\caffe_gpu\caffe\build\include
D:\Projects\caffe_gpu\caffe\build
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\include\boost-1_61
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\include
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.\include
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\include\opencv
D:\Projects\caffe_gpu\caffe\include
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\Include
其中tingpan改成自己电脑的用户名。
(2) “C/C++” –>“预处理器”—> “预处理器定义”, 输入如下:
WIN32
_WINDOWS
NDEBUG
CAFFE_VERSION=1.0.
BOOST_ALL_NO_LIB
USE_LMDB
USE_LEVELDB
USE_CUDNN
USE_OPENCV
CMAKE_WINDOWS_BUILD
GLOG_NO_ABBREVIATED_SEVERITIES
GOOGLE_GLOG_DLL_DECL=__declspec(dllimport)
GOOGLE_GLOG_DLL_DECL_FOR_UNITTESTS=__declspec(dllimport)
H5_BUILT_AS_DYNAMIC_LIB=
CMAKE_INTDIR="Release"
(3)“链接器” –>”输入” –>“附加依赖项”
kernel32.lib
user32.lib
gdi32.lib
winspool.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
comdlg32.lib
advapi32.lib
D:\Projects\caffe_gpu\caffe\build\install\lib\caffe.lib
D:\Projects\caffe_gpu\caffe\build\install\lib\caffeproto.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\lib\boost_system-vc140-mt-1_61.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\lib\boost_thread-vc140-mt-1_61.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\lib\boost_filesystem-vc140-mt-1_61.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\lib\glog.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\Lib\gflags.lib
shlwapi.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\lib\libprotobuf.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\lib\caffehdf5_hl.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\lib\caffehdf5.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\cmake\..\lib\caffezlib.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\lib\lmdb.lib
ntdll.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\lib\leveldb.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\cmake\..\lib\boost_date_time-vc140-mt-1_61.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\cmake\..\lib\boost_filesystem-vc140-mt-1_61.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\cmake\..\lib\boost_system-vc140-mt-1_61.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\lib\snappy_static.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\lib\caffezlib.lib
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.\lib\x64\cudart.lib
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.\lib\x64\curand.lib
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.\lib\x64\cublas.lib
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.\lib\x64\cudnn.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\x64\vc14\lib\opencv_highgui310.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\x64\vc14\lib\opencv_imgcodecs310.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\x64\vc14\lib\opencv_imgproc310.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\x64\vc14\lib\opencv_core310.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\lib\libopenblas.dll.a
C:\Users\tingpan\AppData\Local\Programs\Python\Python35\libs\python35.lib
C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\lib\boost_python-vc140-mt-1_61.lib
去掉勾选 “从父级或项目默认设置继承”。其中tingpan改成自己电脑的用户名。
(4)将D:\Projects\caffe_gpu\caffe\build\install\bin添加到环境变量。
5、编译
如果出现一些错误,提示缺少dll库文件,则从C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\x64\vc14\bin\或C:\Users\tingpan\.caffe\dependencies\libraries_v140_x64_py35_1.1.0\libraries\bin\中拷贝对应的dll文件到D:\Projects\caffe_gpu\caffe\build\install\bin目录下。
6、测试
参数输入:
model/deploy_gender2.prototxt model/gender_net.caffemodel model/deploy_age2.prototxt model/age_net.caffemodel model/mean.binaryproto img/.jpg
输出结果如下:
7、说明
deploy_age2网络结构
deploy_gender2网络结构
性别估计和年龄估计使用的是相同的网络结构,不同之处在于年龄估计fc8层的输出个数为8,而年龄估计的输出个数为2。