1.常用編譯需要的軟件
首先安裝必要軟件
sudo apt install make cmake
編譯GPU版需要安裝驅動
chmod 777 NVIDIA-Linux-x86_64-410.73.run
sudo ./NVIDIA-Linux-x86_64-410.73.run --no-opengl-files
# --no-opengl-files適合筆記本用戶安裝,可以防止桌面分辨率異常,臺式機可以不加
chmod 777 cuda_9.0.176_384.81_linux.run
sudo ./cuda_9.0.176_384.81_linux.run
# cuda安裝時候提示安裝驅動,選n
2.安裝caffe需要的庫
sudo apt install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt install --no-install-recommends libboost-all-dev
sudo apt install libatlas-base-dev
sudo apt install libgflags-dev libgoogle-glog-dev liblmdb-dev
3.根據自己配置修改Makefile.config,主要是是否使用cudnn、僅使用CPU、cuda9注意刪除CUDA_ARCH 中的20和21兩行
4.編譯
make all
注意
1 如果報錯如下,protobuf版本不一致
.build_release/src/caffe/proto/caffe.pb.h:17:2: error: #error This file was generated by an older version of protoc which is
默認protobuf爲3.0版本,舊版2.5版本安裝如下
wget http://archive.ubuntu.com/ubuntu/pool/main/p/protobuf/libprotobuf8_2.5.0-9ubuntu1_amd64.deb
wget http://archive.ubuntu.com/ubuntu/pool/main/p/protobuf/libprotobuf-lite8_2.5.0-9ubuntu1_amd64.deb
wget http://archive.ubuntu.com/ubuntu/pool/main/p/protobuf/libprotobuf-dev_2.5.0-9ubuntu1_amd64.deb
sudo dpkg -i libprotobuf8_2.5.0-9ubuntu1_amd64.deb libprotobuf-lite8_2.5.0-9ubuntu1_amd64.deb libprotobuf-dev_2.5.0-9ubuntu1_amd64.deb
更多庫下載
https://ubuntu.pkgs.org/14.04/ubuntu-main-amd64/libprotobuf-lite8_2.5.0-9ubuntu1_amd64.deb.html
2 如果報錯如下,爲g++版本不兼容
src/caffe/layers/contrastive_loss_layer.cpp:56:30: error: no matching function for call to ‘max(float, double)’
Dtype dist = std::max(margin - sqrt(dist_sq_.cpu_data()[i]), 0.0);
通過安裝低版本gcc g++解決
sudo apt install gcc-4.8 g++-4.8
cd /usr/bin
sudo ln -s gcc-4.8 gcc
sudo ln -s g++-4.8 g++
3 如果報錯如下,anaconda庫衝突
CXX/LD -o .build_release/tools/upgrade_net_proto_text.bin
.build_release/tools/upgrade_net_proto_text.o: In function `main':
/usr/include/c++/5/bits/basic_string.tcc:219: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglog.so: undefined reference to `vtable for std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
在makefile.config修改include路徑lib路徑等,編譯pycaffe時再添加Python的include路徑lib路徑
# Whatever else you find you need goes here.
#INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include $(CUDNN_PATH)
#LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib $(CUDNN_PATH)
INCLUDE_DIRS := /usr/local/include /usr/include/hdf5/serial /usr/include/python2.7 $(CUDNN_PATH)
LIBRARY_DIRS := /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial $(CUDNN_PATH)
4 cublas報錯
F1030 16:15:43.990840 1937 math_functions.cu:28] Check failed: status == CUBLAS_STATUS_SUCCESS (13 vs. 0) CUBLAS_STATUS_EXECUTION_FAILED
安裝CUDA9.0會出現以上錯誤
通過安裝補丁Patch 2 (Released Mar 5, 2018)解決
訓練模型