记录一下安装过程和错误,给自己提醒...
这次装了C3D,因为要用3d卷积核,其实编译过程和普通caffe一样
显卡:NVIDIA GTX 1050Ti
系统:Ubuntu16.04
安装过程参考如下博客,谢谢各位大佬!
ubuntu16.04安装caffe
爆详细Ubuntu16.04,CUDA8.0,OpenCV3.1,Tensorflow完全配置指南
Ubuntu 16.04安装Matlab R2016b
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
如果出现如下界面,表示安装成功
去CUDA官网下载run文件https://developer.nvidia.com/cuda-downloads
我的是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,说明成功
我选择的是intel的mkl,去intel官网下载,需要注册。https://software.intel.com/en-us/qualify-for-free-software/student
进入下载目录解压并安装
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
我下载的是2.7版本,如果要用python3的话,就下3.6 https://www.anaconda.com/download/#linux
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接口出错)
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比百度靠