1. 程式人生 > >caffe實現年齡及性別預測

caffe實現年齡及性別預測

工程 stat pad play app 進入 end iat back

一、相關代碼及訓練好的模型

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.
0\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.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=1 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.0\lib\x64\cudart.lib
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64\curand.lib
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64\cublas.lib
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\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/0008.jpg

輸出結果如下:

技術分享圖片

技術分享圖片

caffe實現年齡及性別預測