Windows7下caffe-ssd-microsoft下編譯


整個編譯可謂漫長 編譯了兩天 網上教程也很多 但是也很雜 遇到各種錯誤 總歸是編完了

 

1、下載Windows版本的Caffe-SSD源碼 
下載鏈接:https://github.com/conner99/caffe,選擇ssd-microsoft 分支; 
2、編譯caffe 
1)、打開caffe-ssd-microsoft文件夾,然后看到一個windows文件夾,然后繼續打開windows文件夾,看到里面一個CommonSettings.props.example文件,復制出來一份,並改名字為CommonSettings.props; 

2)、修改CommonSettings.props文件,選擇gpu或是cpu以及cuda版本,這里選擇的是GPU編譯和Cuda7.5;這里寫圖片描述 
3、編譯問題解決 
1)、設置libcaffe為啟動項,進行編譯,報錯:與boost相關的regex正則表達式庫出現問題,在項目中我們不需要正則表達式,所以將相關語句注釋掉即可; 
解決方法: 
進入項libcaffe中,進入detection_output_layer.hpp中,將與regex相關頭文件注釋掉; 

進入detection_output_layer.cpp文件,將所有出現regex和rv的語句注釋掉; 

進入detection_output_layer.cu文件,將所有出現regex和rv的語句注釋掉; 

2)、編譯工程,報錯:expected an identifier in caffe.pb.h; 
解決方法:修改bbox_util.cu,注釋掉所有帶thrust的語句; 

3)、編譯工程,報錯:找不到”.\caffe\3rdparty\hungarian.h”文件; 
編譯工程,報錯:找不到”.\src\caffe\3rdparty\hungarian.cpp”文件; 
解決方法: 
在路徑.\caffe-master\include\caffe\3rdparty\下添加hungarian.h文件; 
在路徑.\caffe-master\src\caffe\3rdparty\下添加hungarian.cpp文件; 
在這里找這個文件,鏈接:http://pan.baidu.com/s/1mhYuf7y 密碼:3jp2; 

接下來這個一定要改,不改的話會反覆出現類似於:error MSB3721: 命令“"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\bin\nvcc.exe" ....等錯誤。我本人在此被坑幾天,頭髮都掉了一地,哎。這裏的解決辦法是在detection_output_layer.cu,detection_output_layer.cpp兩個文檔中註釋掉所有出現的regex和rv的語句;然後再detection_output_layer.hpp中將語句#include <boost/regex.hpp>註釋掉。

此外,在libcaffe項目下的bbox_util.cu文檔,註釋掉thrust相關的內容,如下所示:  //#include "thrust/functional.h"  //#include "thrust/sort.h"

.....  

//thrust::sort_by_key(&confidence[0],&confidence[0]+num_remain,&idx[0],  

//thrurst::greater<Dtype>());*/  

5 上面的執行完畢之後,恭喜你基本上可以生成libcaffe、caffe.exe文檔,先編譯libcaffe,再caffe(一般都是Release下)。

 

另外我還遇到了

protobuf版本沖突的問題,如下:

  1. In file included from .build_release/src/caffe/proto/caffe.pb.cc:5:0:  
  2. .build_release/src/caffe/proto/caffe.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is  
  3.  #error This file was generated by a newer version of protoc which is  
  4.   ^  
  5. .build_release/src/caffe/proto/caffe.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update  
  6.  #error incompatible with your Protocol Buffer headers.  Please update  
  7.   ^  
  8. .build_release/src/caffe/proto/caffe.pb.h:14:2: error: #error your headers.  
  9.  #error your headers.  
  10.   ^  
  11.   ...  


這個問題的出現是因為我們在安裝caffe之前,安裝Anaconda或tensorflow時都已經安裝過libprotobuf,所以解決沖突的方法是使用以下命令

conda uninstall libprotobuf  

即可解決。

 

 

該解決方案來源於https://stackoverflow.com/questions/36678292/caffe-error-with-protobuf-version

 

全都編譯完了 可以看下目錄應該有這些 exe

 

SSD測試:

新建ssd_detect.bat文件,運行; 
ssd_detect.bat文件內容: 
(1)ssd_detect.exe路徑; 
(2)model_file路徑,即deploy.prototxt; 
(3)weights_file路徑,即XXX.caffemodel; 
(4)test.txt圖片路徑,將圖片的絕對路徑寫入test.txt中; 
(5)–file_type image,此處還可以進行video檢測,可自行看源碼修改; 
(6)–confidence_threshold 0.5; 

注意release和X64等配置,接下來是pycaffe的編譯,步驟也同上,

我遇到了錯誤 no module named _caffe

 先把 F:\caffe-ssd\Build\x64\Release\pycaffe里的caffe復制到F:\caffe-ssd\python里 替代原有的caffe 

再把F:caffe-ssd\Build\x64\Release\pycaffe下的caffe文件夾復制到Anaconda2\Lib\site-packages文件夾下

類似下圖

6.在pycharm中測試一下,可能會出現No module named google.protobuf.internal的問題。

 

解決方法:下載protobuf的兩個文件(地址:https://github.com/google/protobuf/releases/tag/v3.0.0),一個是protoc-3.0.0-win32.zip,一個是Source code (zip)

解壓縮,將protoc-3.0.0-win32\bin\protoc.exe 拷貝進入protobuf-3.0.0源代碼文件夾下src文件夾里,進入protobuf-3.0.0源代碼文件夾下python文件夾,按住shift右擊選擇“在此處打開命令窗口”,執行 python setup.py build 、執行 python setup.py install

這時caffe已經在pycharm里配置成功了,趕快試一下吧。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM