上周安装环境,遇到各种问题,重装系统共计四次!记录一下安装过程,方便以后配置新机器
显卡:GTX1080
系统 ubuntu 16.04 LTS
驱动:Nvidia-384.xx
opencv3.0
这里只配置opencv,没有配置python和matlab,后期会补上流程。
流程:1.安装显卡驱动。2.安装cuda。3.cuDNN。 4.opencv 。5.caffe
期间会涉及 GCC版本不兼容问题,若安装遇到问题,百度无解,请尝试更改GCC版本!(血的经验教训)
第一步.安装相关依赖项
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
第二步,安装驱动:
参照http://blog.csdn.net/xierhacker/article/details/53035989
卸载你电脑中此刻有的nvidia的驱动
sudo apt-get remove –purge nvidia*
添加一个PPA到系统
sudo add-apt-repository ppa:graphics-drivers/ppa
更新
sudo apt-get update
按CTRL+ATL+F1进入终端1 ,注意!需要手机或者另外一台电脑记录命令,因为即将进入非图像界面。
如果需要登录,请用账号,密码登录之
在字符界面输入
sudo service lightdm stop
sudo apt-get install nvidia-384
( 具体是 nvidia-XXX,针对自己GPU上官网查找
参照 http://www.nvidia.com/Download/index.aspx?lang=en-us)
要等个十几二十分钟,安装之后
sudo service lightdm start
进入图形界面(进不去,重启之后,可以进去了)
第三步,安装CUDA8.0
首先把gcc降级,参照 https://www.cnblogs.com/longmao-yiran/p/6832374.html
安装gcc4.9
sudo apt-get install gcc-4.9 g++-4.9
删除gcc5.0的链接
cd /usr/bin
然后
sudo rm gcc sudo rm g++
再建个软连接
sudo ln -s gcc-4.9 gcc sudo ln -s g++-4.9 g++
正式安装cuda8.0 下载好 cuda_8.0.27_linux.run
执行以下命令:
sudo sh cuda_8.0.27_linux.run
会出一大堆说明, 一直按空格,然后 输入 accept , 然后问是否安装驱动361.77,一定要 N ! 往后的全是yes。
安装成功后会出现如下界面:
Summary
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-8.0
Samples: Installed in /home/textminer
Please make sure that
– PATH includes /usr/local/cuda-8.0/bin
– LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin
Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.
To install the driver using this installer, run the following command, replacing with the name of this run file:
sudo .run -silent -driver
Logfile is /opt/temp//cuda_install_6583.log
配置环境变量:
打开文件
sudo gedit ~/.bashrc
在末尾添加两行:
export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
保存,关闭文档
在设置动态链接库
sudo gedit /etc/profile
在打开的文件末尾加入:
export PATH=/usr/local/cuda/bin:$PATH
创建链接文件:
sudo gedit /etc/ld.so.conf.d/cuda.conf
在打开的文件中(文件是空的,不要怕)添加如下语句:
/usr/local/cuda/lib64
然后执行
sudo ldconfig
执行上面的语句,则让其生效
这里需要重新启动电脑
重启,如果出现 Error found when loading /etc/profile:
那是因为 export PATH=/usr/local/cuda/bin:$PATH 的等号两边有空格!
用自带的例子测一下, 进入
cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
sudo make ./deviceQuery
显示一系列信息,说明正确
第四步,cuDNN
下载cuDNN5.1之后进行解压,cd进入cuDNN5.1解压之后的include目录,在命令行进行如下操作:
sudo cp cudnn.h /usr/local/cuda/include/
#复制头文件
再将cd进入lib64目录下的动态文件进行复制和链接:
sudo cp lib* /usr/local/cuda/lib64/
#复制动态链接库
cd /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.5 #删除原有动态文件
sudo ln -s libcudnn.so.5.0.5 libcudnn.so.5 #生成软衔接
sudo ln -s libcudnn.so.5 libcudnn.so #生成软链接
第五步 安装OpenCV3.0
(参照http://blog.csdn.net/xierhacker/article/details/53035989)
任意地方新建文件夹,命名为OpenCV,进入目录,从git上下载openc(没安装 git的,需要: sudo apt install git)
cd Opencv
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
安装依赖(官方给出的):
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/opencv 下面建立新文件夹 build
cd opencv
mkdir build
cd build
设置 cmake
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
(关注ippicv是否下载成功, 28M的,进入到文件夹里面刷新看是否在下载。文件夹: 3rdparty —> ippicv —> downloads —> linux-xxxxxxxxxxxxxxxx )
然后打开 opencv-3.0.0\Cmakelist.txt
将 with_cuda 改成 OFF
在graphcuts.cpp中将
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) 改为 #if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)
开始编译 :
sudo make -j4
开始安装:
sudo make install
第六步 安装caffe
1.装依赖:
sudo apt-get update
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
下载好caffe-master,解压。需要配置Makefile以及修改makefile文件里一句话,才可以编译。
配置Makefile:
sudo cp Makefile.config.example Makefile.config
sudo gedit Makefile.config
修改makefile:
大概在 409行 将
NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
替换
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
开始编译:
make all -j4