1 安裝 NVIDIA 、CUDA 伤哺、CUDNN (版本搭配)
參考: http://www.reibang.com/p/ea8d69fa9cb1
2移除python2.7默認版本(可選)
移除python2.7默認版本
3.從源代碼編譯Opencv
參考:
https://blog.csdn.net/qq_34650787/article/details/80246521
4 燎斩。編譯caffe
(1)下載源碼 (2種版本都可)
1.git clone https://github.com/BVLC/caffe.git
2.git clone https://github.com/weiliu89/caffe/tree/ssd
(2)安裝caffe環(huán)境依賴
1.sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev
libopencv-dev libhdf5-serial-dev protobuf-compiler
2. sudo apt-get install --no-install-recommends libboost-all-dev
3. sudo apt-get install libatlas-base-dev python-dev
4. sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
(2)解壓后修改 Makefile.config文件
cp Makefile.config.example Makefile.config
下面為我的Makefile.config文件
Makefile.config
(3)下載python 環(huán)境依賴包 :
去到 caffe根目錄中的python目錄中運行:
pip3 install -r requirements.txt
(4)設(shè)置系統(tǒng)python環(huán)境
vim ~/.bashrc
export PYTHONPATH="/home/james/caffe-ssd/python"
5 九昧、編譯caffe
在caffe根目錄中依次運行下面代碼 ( -j32 是電腦的核數(shù))根據(jù)自己電腦選擇
如果出錯找到解決辦法后 make clean 重新編譯
make all -j32
make test -j32
make pycaffe
make runtest -j32
**6 、所遇到的問題及解決的辦法:
(1)******caffe 錯誤總結(jié) “/usr/bin/ld: 找不到 -lopencv_imgcodecs”
*opencv 版本問題
https://blog.csdn.net/xw2017/article/details/85230744
https://blog.csdn.net/Dillon2015/article/details/79858116
(2)make caffe (runtest)出現(xiàn)
Makefile:523: recipe for target 'runtest' failed
make: *** [runtest] Error 1
解決方法 : export MKL_CBWR=AUTO
(3)make caffe (runtest)出現(xiàn)
*cuda 版本不合適()或是makefire.config文件中有關(guān)cuda能力的內(nèi)容問題
F0710 15:55:12.340016 4580 test_gradient_based_solver.cpp:80] Check failed: error == cudaSuccess (35 vs. 0) CUDA driver version is insufficient for CUDA runtime version
*** Check failure stack trace: ***
@ 0x7fdd1ca525cd google::LogMessage::Fail()
@ 0x7fdd1ca54433 google::LogMessage::SendToLog()
@ 0x7fdd1ca5215b google::LogMessage::Flush()
@ 0x7fdd1ca54e1e google::LogMessageFatal::~LogMessageFatal()
@ 0x5108e3 caffe::GradientBasedSolverTest<>::TestLeastSquaresUpdate()
-1 查看自己電腦顯卡算力:
https://blog.csdn.net/goodxin_ie/article/details/89057095
-2 Ubuntu16.04下cuda和cudnn的卸載和升級
https://blog.csdn.net/wanzhen4330/article/details/81704474
**(4)caffe安裝時make runtest出錯,有關(guān)libcudart.so.10.0的問題
.build_release/tools/caffe
.build_release/tools/caffe: error while loading shared libraries: libcudart.so.10.0: cannot open shared object file: No such file or directory
make: *** [runtest] 錯誤 127
解決辦法::http://www.reibang.com/p/cf5d59826d60
將cuda的bin文件和lib導出到系統(tǒng)環(huán)境中风宁,版本不一樣則更換其中cuda-x.x
export PATH="/usr/local/cuda-10.0/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH"
或者
vi ~/.bashrc
export PATH="/usr/local/cuda-10.0/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH"
source ~/.bashrc
所需的libcudart.so.8.0如果正確安裝的話,以下兩種方法同理:
sudo ldconfig /usr/local/cuda-8.0/lib64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib64
如果仍然不行蛹疯,再嘗試執(zhí)行:
export PATH=\$PATH:/usr/local/cuda-8.0/bin
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda-8.0/lib64
source /etc/profile
**(5)CUDA報錯: Cannot create Cublas handle. Cublas won't be available. 以及:Check failed: status == CUBLAS_STATUS_SUCCESS (1 vs. 0) CUBLAS_STATUS_NOT_INITIALIZED
解決方法:https://www.bbsmax.com/A/n2d9Y0avdD/
**(6)make all 報錯:
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: cannot find -lhdf5_hl
/usr/bin/ld: cannot find -lhdf5
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 文件(注意不是)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
**(7)make py 報錯:
/usr/bin/ld: cannot find -lboost_python3
collect2: error: ld returned 1 exit status
Makefile:501: recipe for target 'python/caffe/_caffe.so' failed
解決辦法〗洳啤: 設(shè)置numpy路徑
python
import numpy as np
np.__file__
**(8)Ubuntu安裝Caffe .build_release/tools/caffe: error while loading shared libraries: libcudart.so.10.0
執(zhí)行
sudo cp /usr/local/cuda-10.0/lib64/libcudart.so.10.0 /usr/local/lib/libcudart.so.10.0 && sudo ldconfig
sudo cp /usr/local/cuda-10.0/lib64/libcublas.so.10.0 /usr/local/lib/libcublas.so.10.0 && sudo ldconfig
sudo cp /usr/local/cuda-10.0/lib64/libcurand.so.10.0 /usr/local/lib/libcurand.so.10.0 && sudo ldconfig
**(9)
Ubuntu安裝Caffe .build_release/tools/caffe: error while loading shared libraries: libcudnn.so.7
執(zhí)行
sudo cp /usr/local/cuda-10.0/lib64/libcudnn.so.7 /usr/local/lib/libcudnn.so.7 && sudo ldconfig
**(10)import caffe出錯 :
Ubuntu 16.04下安裝Caffe解決 undefined symbol: _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE
Google該錯誤,發(fā)現(xiàn)原因是boost_python的版本不匹配捺弦,默認python版本為3.5饮寞,而boost_python為2.7孝扛。
解決方法:
先在系統(tǒng)的/usr/lib/x86_64-linux-gnu/路徑下查找boost_python文件的版本是否與python版本匹配,我的電腦中文件名為:
libboost_python-py35.so.1.58.0
說明版本為python3.5幽崩,匹配苦始。若不匹配則安裝對應(yīng)的boost_python版本。
接下來打開Caffe文件夾下的Makefile文件慌申,將第208行的
PYTHON_LIBRARIES := boost_python python2.7
改為
PYTHON_LIBRARIES := boost_python-py35 #py35需要改為你自己的python版本陌选,如py34,py33
接著重新編譯文件:
make clean
sudo ldconfig
make caffe
make all
make test
make pycaffe
make runtest