Windows7下caffe-ssd-microsoft下編譯

整個編譯可謂漫長 編譯了兩天 網上教程也不少 可是也很雜 遇到各類錯誤 總歸是編完了python

 

一、下載Windows版本的Caffe-SSD源碼 
下載連接:https://github.com/conner99/caffe,選擇ssd-microsoft 分支; 
二、編譯caffe 
1)、打開caffe-ssd-microsoft文件夾,而後看到一個windows文件夾,而後繼續打開windows文件夾,看到裏面一個CommonSettings.props.example文件,複製出來一份,並更名字爲CommonSettings.props; git

2)、修改CommonSettings.props文件,選擇gpu或是cpu以及cuda版本,這裏選擇的是GPU編譯和Cuda7.5;這裏寫圖片描述 
三、編譯問題解決 
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; github

接下來這個必定要改,不改的話會反覆出現類似於: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"windows

.....  ide

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

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

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

 

另外我還遇到了spa

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裏配置成功了,趕快試一下吧。

相關文章
相關標籤/搜索