2021-05-12 14:32:11
Ubuntu 16.04+CUDA8.0+cuDNN7.5+Caffe安裝過程
Ubuntu 16.04+CUDA8.0+cuDNN7.5+Caffe安裝過程,需要實現下載檔案:
1 U 盤安裝 ubuntu 16.04(ultra + iso )
2 系統進入之後,進入setting -> 軟體和更新 附加驅動 安裝nvidia驅動
3 修改gcc4.9 ( 非必須, 下一步 加override 就行 )
sudo apt-get install g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
4 安裝cuda ./NVIDIA-Linux-XX-XX .run (加 --override!!!) 不要安裝驅動 (驅動處輸入n)!!!!!!!!!!
5 reboot
6 nvidia-settings 選擇Nvidia
7 reboot
8 sudo apt-get install mesa-common-dev
sudo apt-get install freeglut3-dev
9 sudo gedit ~/.bashrc
export PATH=/usr/local/cuda-7.5/bin${PATH:+:${PATH}}export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
10 test :
結果如下所示:
11
cd /usr/local/cuda/samples
sudo make all -j8
。。。。。。
試幾個CUDA例子:
cd /usr/local/cuda/samples/1_Utilities/deviceQuery
./deviceQuery
12 安裝 cudnn
sudo tar -zxvf cudnn-7.5-linux-x64-v5.0-ga.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
Github上有人已經寫好了完整的安裝指令碼:https://github.com/jayrambhia/Install-OpenCV
下載該指令碼,進入Ubuntu/2.4 目錄, 給所有shell指令碼加上可執行許可權
chmod +x *.sh
然後安裝最新版本 (當前為2.4.9)
sudo ./opencv2_4_9.sh
指令碼會自動安裝依賴項,下載安裝包,編譯並安裝OpenCV。整個過程大概半小時左右。
注意,中途可能會報錯
opencv-2.4.9/modules/gpu/src/nvidia/core/NCVPixelOperations.hpp(51): error: a storage class is not allowed in an explicit specialization
///////////////////////////////////////
自己撰寫::
cd OpenCV
# unzip OpenCV-2.4.9.zip
cd opencv-2.4.9
mkdir build
cd build
#cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_TIFF=ON -D BUILD_EXAMPLES=ON -D CUDA_GENERATION=Auto -D BUILD_NEW_Python_SUPPORT=ON ..
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -DINSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -DBUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -DCUDA_GENERATION=Kepler ..
#cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -DINSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -DBUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -DCUDA_GENERATION=Kepler ..
#cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D //INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON CUDA_GENERATION=Kepler ..
sudo make -j8
sudo make install
sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
cd ../../..
echo "OpenCV 2.4.9 ready to be used"
///////////////////////////////
需要在Cmakelist 新增
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORCE_INLINES")
//////////////////////////////////////
replace NCVPixelOperations.hpp
/////////////////////
------------------------------------------------
14 安裝 Python
sudo apt-get install python-dev python-pip
-----------------------
15 安裝其他
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler
15 安裝MKL
//////////////////
1
許多未定義
重新使用GCC5編譯protobuf glog lbd lbboost opencv
未成功
2
使用初始Makefile 重新開始 , 然後修改 hdf5.h:INCLUDE_DIRS:=$(PYTHON_INCLUDE) /usr/local/include/ usr/include/hdf5/serial/
編譯過程中可能會遇到錯誤,比如./include/caffe/util/cudnn.hpp:8:34: fatal error: caffe/proto/caffe.pb.h: No such file or director,這是因為protobuf和pillow沒有安裝,或者是通過apt-get安裝的。使用pip重新安裝一遍即可解決問題。刪除caffe-mast(提前儲存Makefile.config和Makefile),解壓,解壓重新編譯。
<code class="hljs avrasm has-numbering">pip install protobuf --upgrade -i http://pypi<span class="hljs-preprocessor">.douban</span><span class="hljs-preprocessor">.com</span>/simple pip install pillow --upgrade -i http://pypi<span class="hljs-preprocessor">.douban</span><span class="hljs-preprocessor">.com</span>/simple </code>
You could try to pass an argument (CXX_FLAGS) to the compiler -D_FORCE_INLINES by editing the CMAKE files (for example: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORCE_INLINES")) or makefiles.
So, Open the Makefile and changing the line
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
into
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
For me this was on line 406
真正解決看另一篇文章: caffe 未定義的參照問題 http://www.linuxidc.com/Linux/2016-12/138903.htm
解決之後:
make all -j4
make test
make runtest
本文永久更新連結地址:http://www.linuxidc.com/Linux/2016-12/138902.htm
相關文章