【caffe-windows】 caffe-master 之 matlab介面配置

來源:互聯網
上載者:User

標籤: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源碼如下:

  1.  %參考http://www.aichengxu.com/view/2422137  
  2. clear  
  3. clc  
  4.   
  5. im = imread(‘../../examples/images/cat.jpg‘);%讀取圖片  
  6. figure;imshow(im);%顯示圖片  
  7. [scores, maxlabel] = classification_demo(im, 0);%擷取得分第二個參數0為CPU,1為GPU  
  8. maxlabel %查看最大標籤是誰  
  9. figure;plot(scores);%畫出得分情況  
  10. axis([0, 999, -0.1, 0.5]);%座標軸範圍  
  11. grid on %有網格  
  12.   
  13. fid = fopen(‘synset_words.txt‘, ‘r‘);  
  14. i=0;  
  15. while ~feof(fid)  
  16.     i=i+1;  
  17.     lin = fgetl(fid);  
  18.     lin = strtrim(lin);  
  19.     if(i==maxlabel)  
  20.         fprintf(‘the label of %d is %s\n‘,i,lin)  
  21.         break  
  22.     end  

23. end  

運行結果

 

 

 

【caffe-windows】 caffe-master 之 matlab介面配置

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.