標籤:x64 tool 開啟 nts 點擊 密碼 opencv dll 函數
平台環境: win10 64位 caffe-master vs2013 Matlab2016a
第一步:
開啟\caffe-master\windows下的CommonSettings.props檔案,
更改MatlabSupport,改成true(即支援Matlab介面)。
第二步:
更改matlab的路徑,
第三步:
在includepath中增加一個路徑,若沒有的話,在編譯時間候會出現如下錯誤:gpu/mxGPUArray.h" Not Found
複製這段code:
<IncludePath>$(MatlabDir)\extern\include;$(MatlabDir)\toolbox\distcomp\gpu\extern\include;$(IncludePath)</IncludePath>
第四步:
開啟caffe-master\windows 下的 Caffe.sln ,找到matcaffe,選擇released(不要用debug),然後右鍵matcaffe,點擊產生。
PS:不知道什麼原因出錯
錯誤 1 error : NuGet Error:Unable to find version‘2.4.10‘ of package ‘OpenCV.overlay-x64_v120_Release‘. D:\NugetPackages\OpenCV.2.4.10\build\native\OpenCV.targets 772 5 libcaffe
選擇重建,可以解決。當然,沒出錯的同學忽略。
產生完畢後在caffe-master\Build\x64\Release\matcaffe\+caffe\private下會有檔案 :caffe_.mexw64
第五步:
開啟matlab,添加路徑
第六步:
添加系統內容變數,把..\caffe-master\Build\x64\Release 添加到系統內容變數中,
否者在運行 demo.m時候出會出現如下錯誤:
Invalid MEX-file‘D:\caffe-master\Build\x64\Release\matcaffe\+caffe\private\caffe_.mexw64‘: 找不到指定的模組。
出錯 caffe.set_mode_cpu (line 5)
caffe_(‘set_mode_cpu‘);
出錯 classification_demo (line 71)
caffe.set_mode_cpu();
第七步:
將caffe-master\Build\x64\Debug中所有dll檔案全複製到caffe-master\matlab\+caffe\private
第八步:
下載model檔案(bvlc_reference_caffenet.caffemodel)放到caffe-master\models\bvlc_reference_caffenet檔案夾下
連結:http://pan.baidu.com/s/1geUv01l密碼:yp9p(出處:http://blog.csdn.net/zb1165048017/article/details/51702686)
第九步:
下載標籤檔案:synset_words.txt ,放在與classification_demo.m同一個檔案夾下
連結:http://pan.baidu.com/s/1c24ty6W密碼:3z7y(出處:http://blog.csdn.net/zb1165048017/article/details/51702686)
第十步:
開啟classification_demo.m,運行。如果出現
未定義函數或變數 ‘caffe_‘。
出錯 caffe.set_mode_cpu (line 5)
caffe_(‘set_mode_cpu‘);
出錯 classification_demo (line 71)
caffe.set_mode_cpu();
請修改 第二條語句
addpath(‘../../Build/x64/Release/matcaffe‘);
第十一步:
在運行一個測試檔案test_mat.m, 檔案出處(出處:http://blog.csdn.net/zb1165048017/article/details/51702686)
下載連結:http://pan.baidu.com/s/1nvtwoBJ 密碼:t71u
存放在與classification_demo.m同一個檔案夾下
test_mat.m源碼如下:
- %參考http://www.aichengxu.com/view/2422137
- clear
- clc
-
- im = imread(‘../../examples/images/cat.jpg‘);%讀取圖片
- figure;imshow(im);%顯示圖片
- [scores, maxlabel] = classification_demo(im, 0);%擷取得分第二個參數0為CPU,1為GPU
- maxlabel %查看最大標籤是誰
- figure;plot(scores);%畫出得分情況
- axis([0, 999, -0.1, 0.5]);%座標軸範圍
- grid on %有網格
-
- fid = fopen(‘synset_words.txt‘, ‘r‘);
- i=0;
- while ~feof(fid)
- i=i+1;
- lin = fgetl(fid);
- lin = strtrim(lin);
- if(i==maxlabel)
- fprintf(‘the label of %d is %s\n‘,i,lin)
- break
- end
23. end
運行結果
【caffe-windows】 caffe-master 之 matlab介面配置