環境:
ubuntu16.04 cuda8.0 cudnn5.0
已安裝過caffe1.0 tensorflow1.2
編輯過程中出現問題盡量到這里面搜一下:https://github.com/BVLC/caffe/issues
教程 https://github.com/weiliu89/caffe/tree/ssd
Installation
- Get the code. We will call the directory that you cloned Caffe into
$CAFFE_ROOT
git clone https://github.com/weiliu89/caffe.git
cd caffe
git checkout ssd
- Build the code. Please follow Caffe instruction to install all necessary packages and build it.
# Modify Makefile.config according to your Caffe installation. cp Makefile.config.example Makefile.config make -j8 # Make sure to include $CAFFE_ROOT/python to your PYTHONPATH. make py make test -j8 # (Optional) make runtest -j8
問題:此處參考了別的教程使用了make all -j8出現問題(一定看官方教程)問題描述:
This file was generated by an older version of protoc which is incompatible with your Protocol Buffer headers. Please regenerate this file with a newer version of protoc.
原因是系統中裝tensorflow時裝有了多個版本的protobuf,造成版本沖突。將protobuf卸載后,按照此教程重新安裝https://www.cnblogs.com/luoxn28/p/5303517.html
tar -xvf protobuf cd protobuf ./configure --prefix=/usr/local/protobuf make make check make install
按照上邊的還有問題,加上這部分
去https://developers.google.com/protocol-buffers/docs/downloads下載*.tar.tz壓縮包,解壓, 命令行進入解壓后目錄,依次執行如下 ./configure make 創建文件 /etc/ld.so.conf.d/libprotobuf.conf 寫入內容:/usr/local/lib 輸入命令 sudo ldconfig 注:protobuf的默認安裝路徑是/usr/local/lib,而/usr/local/lib 不在Ubuntu體系默認的 LD_LIBRARY_PATH 里,后面install找不到該lib 然后sudo make install 安裝后,輸入protoc --version 驗證是否安裝成功
如果還有問題,參考:https://my.oschina.net/ifraincoat/blog/406339
然后輸入protoc --version查看是否安裝成功,報錯:protoc: error while loading shared libraries: libprotoc.so.8: cannot open shared object file: No such file or directory
解決辦法: export LD_LIBRARY_PATH=/usr/local/lib/ (這個可能需要寫到環境變量里,否則會不會下次啟動就不能用了)
裝完一定要清理一下,一定要清理一下!! make clean!!!
install libhdf5-dev add patch to libhdf5 in Makefile.config. example: INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
參考:https://askubuntu.com/questions/629654/building-caffe-failed-to-see-hdf5-h
繼續編譯,新的問題gcc版本過高, /usr/local/cuda/include/host_config.h:119:2: error: #error -- unsupported GNU version! gcc versions
解決方案:降低gcc與g++版本到5,參考https://blog.csdn.net/qq_31175231/article/details/77774971
gcc --verison查看gcc (2)設置gcc的默認版本 設置之前可以先輸入命令ls /usr/bin/gcc* 查看gcc 4.8版本是否安裝成功 然后輸入下面的命令設置默認版本: sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 100 最后的數字為優先級(越大越高),因為只有一個4.8版本作為alternatives,可以不要糾結數字,這樣設就行了 (3)然后可以輸入以下命令查看設置結果(非必須) sudo update-alternatives --config gcc 因為只設置了一個,所以顯示結果為:"鏈接組 gcc (提供 /usr/bin/gcc)中只有一個候選項:/usr/bin/gcc-4.8 無需配置.",如果有多個則會顯示一個按優先級的列表. (4)最后再次輸入命令gcc -version查看gcc的版本已經變成4.8啦...就成功啦. 現在默認版本已經是4.8版本,如果想用6.2版本,則gcc-6.2 這樣指定就好啦 g++ 等其他軟件也是這樣設置進行版本升級/降級. ps: (1)當以上設置不需要的時候輸入以下命令刪除: sudo update-alternatives --remove gcc /usr/bin/gcc-4.8 --------------------- 作者:帝江VII 來源:CSDN 原文:https://blog.csdn.net/qq_31175231/article/details/77774971 版權聲明:本文為博主原創文章,轉載請附上博文鏈接!
繼續編譯,出現問題
/usr/bin/ld: cannot find -lopencv_imgcodecs /usr/bin/ld: cannot find -lopencv_videoio collect2: error: ld returned 1 exit status Makefile:566: recipe for target ‘.build_release/lib/libcaffe.so.1.0.0-rc3’ failed make: * [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1
首先更新Makefile,不知道管沒管用,參考https://blog.csdn.net/sunshinezhihuo/article/details/79427093
然后修改Makefile 文件(注意不是)Makefile.config 將里面的 LIBRARIES += glog gflags
protobuf boost_system boost_filesystem m hdf5_hl hdf5
改為LIBRARIES += glog gflags protobuf boost_system boost_filesystem m
hdf5_serial_hl hdf5_serial
然后還是原問題,根據https://github.com/BVLC/caffe/issues/5308安裝庫
Did you apt-get install libopenblas-base libopenblas-dev ?
繼續編譯,出現問題: .build_release/lib/libcaffe.so: undefined reference to `cv::VideoCapture::set(int, double)' .build_r
solution: add "opencv_imgcodecs" in Makefile.(LIBRARIES += glog gflags protobuf leveldb snappy \ lmdb boost_system hdf5_hl hdf5 m \ opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs) If you input "make all",the problem is the same again.But if you delete all the file in build(rm -rf ./build/*) before "make all"(I use make clean ),you will success.I just success github 討論帖:https://github.com/BVLC/caffe/issues/2348 參考鏈接:https://www.douban.com/note/568788483/
另外opencv_videoio也要加上。
繼續編譯新問題出現 .build_release/lib/libcaffe.so: undefined reference to `boost::filesystem::detail::status(boost::fil
解決方式:再加一個庫boost_filesystem
第一步編譯成功
二:make py
問題:
python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: No such file or directory compilation terminated. Makefile:501: recipe for target 'python/caffe/_caffe.so' failed make: *** [python/caffe/_caffe.so] Error 1
解決方式:
如果還是不行,可以試試: import numpy as np np.get_include() 得到: /usr/local/lib/python2.7/dist-packages/numpy/core/include 在Makefile.config找到PYTHON_INCLUDE,發現有點不同: PYTHON_INCLUDE := /usr/include/python2.7 \ /usr/lib/python2.7/dist-packages/numpy/core/include 要加一個local,變成: PYTHON_INCLUDE := /usr/include/python2.7 \ /usr/local/lib/python2.7/dist-packages/numpy/core/include 再make pycaffe就ok了
參考:https://blog.csdn.net/wuzuyu365/article/details/52430657
三:
不要隨便make clean 否則會出現 make: .build_release/tools/caffe: Command not found
解決方式:make all 參考:https://blog.csdn.net/xunan003/article/details/72997028
問題: Makefile:526: recipe for target 'runtest' failed make: *** [runtest] Segmentation fault
解決方案:sf@ubuntu:~/caffe$ export MKL_CBWR=AUTO
不要make clean,然后重新make runtest
這個問題沒有解決,但是看網上資料說這個不用全部運行成功也可以,就沒有繼續調試
然后在python環境下imoprt python,報錯 ImportError: No module named caffe
solution:
A.把環境變量路徑放到 ~/.bashrc文件中,打開文件 sudo vim ~/.bashrc 在文件下方寫入 export PYTHONPATH=~/caffe/python:$PYTHONPATH 上述語句中 “~” 號表示caffe 所在的根目錄。 B.關閉文件,在終端寫入下面語句,使環境變量生效 source ~/.bashrc --------------------- 作者:修煉打怪的小烏龜 來源:CSDN 原文:https://blog.csdn.net/u010417185/article/details/53559107 版權聲明:本文為博主原創文章,轉載請附上博文鏈接!
繼續import,報錯 ImportError: No module named google.protobuf.internal
solution: sudo pip install protobuf
