記錄一下安裝過程和錯誤,給自己提醒...
這次裝了C3D,因為要用3d卷積核,其實編譯過程和普通caffe一樣
顯示卡:NVIDIA GTX 1050Ti
系統:Ubuntu16.04
安裝過程參考如下部落格,謝謝各位大佬!
ubuntu16.04安裝caffe
ctrl+alt+t開啟終端
新增官方源
$ sudo add-apt-repository ppa:graphics-drivers/ppa
然後去nvidia官網查一下自己的顯示卡驅動,www.nvidia.cn/Download/index.aspx?lang=cn 我的是384,所以下面輸的是nvidia-384
1.$ sudo apt-get update
2.$ sudo apt-get install nvidia-384 nvidia-settings nvidia-prime
安裝完之後重啟電腦,看是否安裝成功
$ nvidia-settings
如果出現如下介面,表示安裝成功
我的是cuda9.0。下載好之後cd到檔案所在位置
sudo ./cuda_9.0.176_384.81_linux.run --override
出現這個表示安裝正確
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-9.0
Samples: Installed in /usr/local/cuda-9.0, but missing recommended librarie
接下來下載cudnn,需要先註冊,選library for linux,https://developer.nvidia.com/cudnn
到下載的檔案所在的目錄解壓,我的檔案都在home裡
1.tar zxvf cudnn-9.0-linux-x64-v7.tgz
2.cd cuda/include/
3.sudo cp cudnn.h /usr/local/cuda/include/ #複製標頭檔案
4.cd ..
5.cd lib64/
6.sudo cp lib* /usr/local/cuda/lib64/ #複製動態連結庫
#建立新的連結
7.cd /usr/local/cuda/lib64/
8.sudo rm -rf libcudnn.so libcudnn.so.7
9.sudo ln -s libcudnn.so.7.0.3 libcudnn.so.7
10.sudo ln -s libcudnn.so.7 libcudnn.so
設定環境變數
gedit ~/.bashrc
把下面的路徑加進去,=兩邊不要有空格
export PATH=/usr/local/cuda/bin:$PATH
儲存後建立連結檔案
1.sudo vim /etc/ld.so.conf.d/cuda.conf
2.#按下鍵盤i進行編輯
3./usr/local/cuda/lib64
4.#按esc,按:wq儲存退出
#使連結生效
5.sudo ldconfig
可能會有提示vim未安裝,搜一下vim安裝教程,安裝一下vim就行了vim安裝與配置
編譯sample
$ cd /usr/local/cuda/samples
$ sudo make all -j8
$ cd /usr/local/cuda/samples/bin/x86_64/linux/release
$ sudo ./deviceQuery
出現Result=PASS,說明成功
進入下載目錄解壓並安裝
1.tar zxvf parallel_studio_xe_2017.tgz
2.cd parallel_studio_xe_2017/
3.sudo ./install_GUI.sh
按提示步驟安裝即可
安裝完之後,對相關檔案進行連結
sudo gedit /etc/ld.so.conf.d/intel-mpi-2017.0.098.conf
新增庫檔案 立即生效
sudo ldconfig
先安裝相關依賴
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install --assume-yes libopencv-dev libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip
sudo apt-get install ffmpeg libopencv-dev libgtk-3-dev python-numpy python3-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libv4l-dev libtbb-dev qtbase5-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev
在你喜歡的位置建個OpenCV資料夾,我在home新建了資料夾,然後下載OpenCV
1.mkdir OpenCV
2.cd OpenCV
3.git clone https://github.com/opencv/opencv.git
4.git clone https://github.com/opencv/opencv_contrib.git
下載過程會比較慢,下載完成後你的OpenCV資料夾裡應該有兩個資料夾,一個是opencv,一個是opencv_contrib,我們在opencv資料夾裡新建一個build資料夾,用來接收cmake的各種檔案,然後進入到build資料夾
1.mkdir OpenCV/opencv/build
2.cd build/
3.
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D BUILD_TIFF=ON -D WITH_QT=ON -D WITH_OPENGL=ON -DCUDA_NVCC_FLAGS="-D_FORCE_INLINES" ..
最後面是空格加兩個點,不要錯了。cmake完之後,build下面也有了檔案,在build裡直接make,這一步時間很長
sudo make -j8
make完成後再
sudo make install
1.掛載iso檔案到linux上
mkdir /media/matlab sudo mount -o loop [你的iso檔案路徑]/R2016a_glnxa64.iso /media/matlab (我的matlab安裝包在home裡,所以這條命令就是,sudo mount -o loop /home/tsing/matlabLinux/R2016a_glnx64.iso /media/matlab)
現在matlab應該已經掛載到/media/matlab上了
2.回到主目錄後執行安裝命令
cd
sudo /media/matlab/install
接下來就是安裝引導了(安裝的時候沒有截圖,借了www.linuxidc.com/Linux/2017-03/142298.htm
的圖,安裝步驟也是參考這個網址)
選擇use a file installation key,然後next
選擇yes
序列號在crack資料夾的FIK裡,直接複製貼上過去,然後next,接下來就是等待安裝了
3.啟用matlab
matlab一般預設安裝到/usr/local/MATLAB/R2016a/bin
cd /usr/local/MATLAB/R2016a/bin
./matlab
選擇用本地許可證檔案啟用,選擇home裡matlabLinux/crack裡的lic檔案就可以了,然後就啟用成功
4.
將matlabLinux/crack裡的libcufft.so.7.5.18和libmwservices.so複製到/usr/local/MATLAB/R2016a/bin/glnxa64
cd /home/tsing/matlabLinux/crack
cp libcufft.so.7.5.18 /usr/local/MATLAB/R2016a/bin/glnxa64
cp libmwservices.so /usr/local/MATLAB/R2016a/bin/glnxa64
5.取消掛載,刪除空資料夾
umount /media/matlab
rm -rf /media/matlab
cd到下載目錄
sudo bash Anaconda2-5.0.1-Linux-x86_64.sh
安裝完以後在環境變數新增anaconda庫檔案路徑
sudo gedit ~/.bashrc
在bashrc末尾加入
export PATH="/home/tsing/anaconda2/bin:$PATH"
export LD_LIBRARY_PATH="/home/tsing/anaconda2/lib:$LD_LIBRARY_PATH"
然後立即生效
source ~/.bashrc
這時候在終端輸入python,應該就能看到python版本了
1.首先安裝caffe依賴
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential cmake git pkg-config
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install -y libatlas-base-dev
sudo apt-get install -y --no-install-recommends libboost-all-dev
sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install -y python-pip
sudo apt-get install -y python-dev
sudo apt-get install -y python-numpy python-scipy
sudo apt-get install -y libopencv-dev
2.下載caffe(C3D)
回到home
cd
git clone https://github.com/BVLC/caffe.git
(如果下載C3D:
git clone https://github.com/facebook/C3D.git)
等待下載完成
C3D下載完之後裡面會有C3D-v1.0和C3D-v1.1,只需要v1.1,所以我就把C3D-v1.1放到home了
3.安裝配置
C3D的安裝配置和caffe一樣,接下來就按照caffe路徑寫了,配置C3D的時候記得改命令裡相應的資料夾名稱
cd caffe
cp Makefile.config.example Makefile.config
sudo gedit Makefile.config
修改配置檔案
USE_CUDNN := 1
OPENCV_VERSION := 3
# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
CUDA_ARCH := #-gencode arch=compute_20,code=sm_20 \
#-gencode arch=compute_20,code=sm_21 \
#-gencode arch=compute_30,code=sm_30 \
#-gencode arch=compute_35,code=sm_35 \
#-gencode arch=compute_50,code=sm_50 \
#-gencode arch=compute_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 \
-gencode arch=compute_61,code=compute_61
BLAS := mkl
MATLAB_DIR := /usr/local/MATLAB/R2016a
ANACONDA_HOME := /home/tsing/anaconda2
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
$(ANACONDA_HOME)/include/python2.7 \
$(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
修改Makefile裡的內容
gedit Makefile
找到
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
替換為
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
將
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
替換為
LIBRARIES += glog gflags protobuf leveldb snappy lmdb boost_system boost_filesystem m hdf5_hl hdf5 m opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_videoio
(防止在編譯C3D時報opencv的錯)
找到
CXXFLAGS += -MMD -MP
在下面加一句(不是替換!!!)
CXXFLAGS += -std=c++11
(防止C3D編譯matlab接口出錯)
配置環境變數
gedit ~/.bashrc
在末尾加上
export LD_LIBRARY_PATH="/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH"
立即生效
ldconfig
為hdf5建立連結
find . -type f -exec sed -i -e 's^"hdf5.h"^"hdf5/serial/hdf5.h"^g' -e 's^"hdf5_hl.h"^"hdf5/serial/hdf5_hl.h"^g' '{}' \;
cd /usr/lib/x86_64-linux-gnu
sudo ln -s libhdf5_serial.so.10.1.0 libhdf5.so
sudo ln -s libhdf5_serial_hl.so.10.0.2 libhdf5_hl.so
編譯caffe
make all -j8
make test -j8
make runtest
如果全都編譯完,沒有報錯,接下來anaconda需要將caffe標頭檔案連結(C3D在runtest時,會有兩個test不通過,但是並不影響使用,all和test全都通過了就可以)
gedit ~/.bashrc
在末尾新增
export PYTHONPATH="/home/tsing/caffe/python:$PYTHONPATH" (C3D的資料夾可能不叫caffe,記得把caffe改成對應的資料夾名字)
ldconfig
caffe根目錄下
make pycaffe
make contribute
ipython
import caffe
如果沒喲報錯的話,caffe和python介面就ok了
cd /usr/local/MATLAB/R2014a/sys/os/glnxa64/
sudo mv libstdc++.so.6 libstdc++.so.6_back
cd ~/caffe/
make matcaffe
make mattest
出現上圖表示編譯成功
1.m//home/tsing/anaconda2/lib/libpng16.so.16:對‘inflateValidate@ZLIB_1.2.9’未定義的引用
在 Makefile.config 中,加入下一句
LINKFLAGS := -Wl,-rpath,$(HOME)/anaconda/lib
2.ImportError: No module named caffe
在環境變數中新增python路徑
gedit ~/.bashrc
加入export PYTHONPATH=~/caffe/python:$PYTHONPATH
ldconfig
3.對LIBTIFF_4.0未定義的引用
可能是許可權問題,我在用了sudo make所有之後就沒有這個錯誤了
4.
fatal error: caffe/proto/caffe.pb.h: No such file or directory
網上說有可能是make太快,我把make all -j8改成make all就沒有這個錯誤了...
感覺這個錯誤很無語...
我可能還出過別的錯誤,但是我暫時想不起來了... 有好多錯誤其實是路徑的問題,把庫所在的位置放到環境變數裡就沒有再報錯了。好多錯誤去google比百度靠