ubuntu14.04+gtx1080+caffe+cuda8.0+matlab2015b以及遇到的问题

    一开始是只菜鸟,linux是啥都闹不清,因为实验室要用caffe研究深度学习,然后自己折腾这玩意不知道折腾了有多久,重装系统不下20次!!!照着人家的教程来,总也遇见人家遇不见的问题,好多时候解决不了,发现最简便的方法竟然只能是——重装,原谅我只是个菜鸟。满满都是辛酸泪啊。然后要感谢一下网上各种大牛们的教程和对各种问题的解答,现在已经能比较快的重新搭建了,把我收集到觉得有用的资源和我的经验和大家分享一下,希望让更多的新手少走弯路。


本机配置:

gpugtx 1080

cup  i7 6800k

系统 Ubuntu14.04 64位

内存 16g

固盘 500g

硬盘 1t

 

参考博文及网址:

匹配本机配置安装教程

http://blog.csdn.net/u010733679/article/details/52249503

 

linux系统ubutu14.04安装包

http://www.oschina.net/news/70826/ubuntu-14-04-4

 

rufus制作启动盘

http://www.iplaysoft.com/rufus.html

 

Ubuntu分区方案参考

http://tieba.baidu.com/p/3562464918

 

Caffe官网安装教程

http://caffe.berkeleyvision.org/install_apt.html

 

cuda官网安装手册

http://developer.download.nvidia.com/compute/cuda/8.0/secure/prod/docs/sidebar/CUDA_Quick_Start_Guide.pdf?autho=1476845246_c5922b2c00b7247482a1919cb3279983&file=CUDA_Quick_Start_Guide.pdf

 

cuda8.0下载地址

https://developer.nvidia.com/cuda-downloads

 

cuda7.5安装参考

http://blog.csdn.net/g0m3e/article/details/51420565

http://blog.csdn.net/xizero00/article/details/43227019

http://blog.csdn.net/ubunfans/article/details/47724341

http://www.ithao123.cn/content-10771366.html

 

cuda8.0安装参考

http://blog.csdn.net/u012177034/article/details/52102676

http://www.2cto.com/os/201607/528798.html

 

折腾纪要

注:请看完整个纪要再自行折腾,我走了一些弯路,不要跟我把弯路一起走了!!!如有觉得不详细或需要安装包等,可自行返回第一页查看是否有相关链接。

 

1、装系统(耗时2星期)

步骤:下载安装包(参照上页链接)——制作启动盘——安装(注意如何分区,主分区最多只能有4个;当然也可以直接默认安装,它会自动帮你分好分区。另,有些电脑需要设置优先U盘启动,本机一开始就是默认u盘驱动)

工作站原本装的是win7,最开始想折腾双系统,但是没闹清楚win7是装在硬盘还是固盘里,一不小心就把win7覆盖了。后来有尝试重装双系统,分别装在不同的盘里,无奈ubuntu怎么折腾都不好使,总是卡机什么,最后不得已卸了win7只留了ubuntu。经对比ubuntu14.04比ubuntu16(直接从官网下是在16这个版本)。现在ubuntu只用了固盘,没有用到硬盘,尝试两个盘一起用时,系统老是抽风,原因未知。

 

2、换中文

安装搜狗输入法,参考http://jingyan.baidu.com/article/ad310e80ae6d971849f49ed3.html

 

   然后参照http://blog.csdn.net/ubunfans/article/details/47724341一步步进行安装,python部分除外——最后本机安的是matlab。中间可能会出现各种问题,需自行百度解决。P.S.请一定按照博文一步步来,因为本纪要省略了一些简单的我也记不住的诸如安装相关依赖库等步骤。

 

3、安装cuda7.5

到cuda官网自行下载安装包,注意对应到ubuntu 64位,有三个版本可选择,分别是 run、 deb(local)、deb(online)

 

尝试一:.deb安装

       优点:简单快捷。

       缺点:因为是打包安装,会自行覆盖原来的显卡驱动,后来一直出现循环登录问题。

       解决方法:卸载本机显卡驱动,到英伟达官网下载对应驱动,关掉xserver,后台安装驱动。

 

尝试二: .run安装

关掉x server(ctri+f1进入后台1,sudo service lightdm stop),运行.run文件(sh   xxxx.run),长按回车键接受协议,协议页面之后安装,除了(第一个还是第二个)问是否安装驱动(driver)不接受,其他均按提示选择y或accept,或者输入对应文件夹名。安装完成后打开x server(sudoservice lightdm start)

 

4、安装对版本的cudnn以及opencv,系统自带gcc版本为4.8,与cuda7.5兼容。(安装cudasample——如果是.run安装则在安装过程中会提示安装cudasample,不需要重新安装)并验证是否安装成功。安装matlab 并创建快捷方式。

 

5、下载安装caffe

下载解压,修改Makefile.config。在caffe目录下make all ,make test, make runtest (后缀 –j16表示16条线程加速,编译会更快),全部通过表示caffe安装成功。

出现问题:make runtest出现一个百度不到的错误,邮件英伟达官网,提议重装cuda8。所以,cuda8.0 才是本机的最终归宿,前面的折腾和相关网页链接作为参考(某些步骤还是不变的)

 

6、重装cuda8.0

从官网下载ubutun 64位对应.run安装包,按照博文(第一页有三个参考)http://blog.csdn.net/u012177034/article/details/52102676

进行安装。重新在caffe文件夹下make run test ,pass。

问题:我并没有删掉cuda7.5,选择将cuda 8.0建立文件连接cuda之后(cuda7.5安装过程中也会有这个选项),cuda文件夹中不仅有cuda 8的东西,也有cuda 7.5的东西。之后我再删掉cuda7.5的文件夹和相关配置,caffe 又跑不动了。

解决方案:更新与cuda 8.0 对应的opencv和gcc

 

7、安装opencv3.1和gcc5.3

    已经忘记是怎么装的了,开始利用apt-getinstall安装的gcc-5是gcc 5.4,好不容易降级成gcc-5.3之后,却无法再更改gcc版本,就算强行卸载掉所有的gcc-5文件,利用gcc –version查询,依然是gcc-5.3.0,然后就出现各种动态库链接问题,超级崩溃,在stackoverflow(在这里推荐这个国外的网站,用于解决各种问题,港真百度不是那么好用,好多东西都要试好几个答案才行)上求问也没有得到答案。因为caffe 的编译需要更低版本的gcc,最后没有办法只有只好重装系统了。

 

 

      重装系统就要重装以上所有的东东,请想象我内心有多么崩溃!!!以下为重装步骤,主要参考

http://blog.csdn.net/u012177034/article/details/52102676     http://blog.csdn.net/u010733679/article/details/52249503   两篇博文,亲测可用

 

可用步骤

1、 重装Ubuntu14.04

 

2、装sogou拼音(没有中文很难过)

   http://jingyan.baidu.com/article/ad310e80ae6d971849f49ed3.html

       从搜狗官网下载匹配系统(Ubuntu14.04 64位)的deb安装包,点击直接安装,然后在终端输入

       im-config

       然后选择fcitx

       重启

       终端输入fcitx-config-gtk3

       去掉当前选项那个勾,然后搜索sogou,选择搜狗拼音,就可以在屏幕右上角输入法位置看到搜狗拼音的小图标了

 

3、装gcc 4.9并切换使用

 

     http://blog.csdn.net/robertchenguangzhi/article/details/47837445

 

4、安装cuda 8.0

     (1)先在cuda官网下载与自己系统对应的.run文件(比deb文件更稳定更好操作),终端输入

 

     cd 安装文件所在文件夹

     sudo sh cuda_8.0xxxxxx.run

     #第一个选项是问是否安装捆绑的显卡驱动,选择否,其他都选是,根据提示来。如图:

 


      (2)然后添加环境变量

     sudo gedit /etc/profile

     #在打开的文件中末尾添加以下两行

   

    export PATH=/usr/local/cuda-8.0/bin:$PATH

      exportLD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH

     #之后保存并退出,在终端执行以下指令使配置生效

     sudo ldconfig

     (3)验证cuda是否安装成功

      

    进入NVIDIA_CUDA-8.0_Samples文件夹,进行make编译。之后进入1_Utilities/deviceQuery/文件夹,运行./deviceQuery命令,若出现Nvidia显卡的型号等信息,则说明安装成功,如图:

 


5、安装cudnn5.1

     从官网下载cudnn(需注册),版本要与cuda8.0匹配。将下载的压缩文件cudnn-8.0-linux-x64-v5.1.tgz解压得到一个叫做cuda的文件夹,执行以下指令:

    

   sudo cp lib64/lib* /usr/local/cuda-8.0/lib64/

    sudo cp include/cudnn.h/usr/local/cuda-8.0/include/

    cd/usr/local/cuda/lib64/

    sudo chmod 777libcudnn*即可

    这里注意,复制完后需要将libcudnn*的权限都改为777,否则后面将不能执行~~~,编译时出现找不到Libcudnn.so或者libcudart.so.8.0文件的情况。

   更新文件链接

   cd /usr/local/cuda/lib64/

  sudo rm -rf libcudnn.so libcudnn.so.5

  sudo ln -s libcudnn.so.5.1.5 libcudnn.so.5

  sudo ln -s libcudnn.so.5 libcudnn.so

    设置环境变量

   sudo gedit /etc/profile

    #在打开的文件中末尾添加

   

     export PATH=/usr/local/cuda/bin:$PATH

 

  sudo vim /etc/ld.so.conf.d/cuda.conf
  #添加文字   /usr/local/cuda/lib64

   sudo ldconfig  #使配置生效

 

6、安装opencv3.1

    安装基本依赖库

    sudoapt-get install build-essential cmake git ibgtk2.0-dev pkg-configlibavcodec-dev libavformat-dev libswscale-dev

     下载opencv安装包,解压后进入安装文件

    

      cdopencv-3.1.0/modules/cudalegacy/src

      sudo gedit graphcuts.cpp

       将相关部分替换为

       #include "precomp.hpp"

        // GraphCut has been removed in NPP 8.0

    #if!defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)

void cv::cuda::graphcut(GpuMat&,GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&,Stream&) { throw_no_cuda(); }

void cv::cuda::graphcut(GpuMat&,GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&,GpuMat&, GpuMat&, GpuMat&, GpuMat&, Stream&) {throw_no_cuda(); }

 

           再次进入安装文件夹

          cd opencv-3.1

          mkdir build

          cd build

            cmake -DCMAKE_BUILD_TYPE=Release-D                              CMAKE_INSTALL_PREFIX=/usr/local ..

           配置完成后安装

           sudo make install

    安装完成后查询是否安装成功

    pkg-config --modversion opencv

 

7、安装依赖项

(1)安装atlas

sudo apt-get install libatlas-base-dev

(2)安装矩阵运算库

sudo apt-get install libopenblas-devlibblas-dev liblapack-dev

(3)protobuf库

sudo apt-get install libprotobuf-devprotobuf-compiler

(4)boost库

sudo apt-get installlibboost-all-dev

(5)GLOG库

sudo apt-get installlibgoogle-glog-dev

(6)LMDB与LEVELDB

sudo apt-getinstall  libleveldb-dev liblmdb-dev

(7)snappy库

sudo apt-getinstall  libsnappy-dev

(8)HDF5库

sudo apt-get install libhdf5-serial-dev

(9)gflags库

sudo apt-get installlibgflags-dev

(10)opencv库

sudo apt-get installlibopencv-dev

 

 

8、安装caffe

    从github上克隆一份caffe项目代码并解压。进入caffe 文件夹,复制一份Makefile.config.examples

  cp Makefile.config.example Makefile.config

    修改其中的一些路径,去掉使用opecv3的注释。如果前边和我说的一致,都选默认路径的话,那么配置文件应该是这个样子

 

## Refer tohttp://caffe.berkeleyvision.org/installation.html

# Contributions simplifying and improving ourbuild system are welcome!

 

# cuDNN acceleration switch (uncomment tobuild with cuDNN).

USE_CUDNN := 1

 

# CPU-only switch (uncomment to build withoutGPU support).

# CPU_ONLY := 1

 

# uncomment to disable IO dependencies andcorresponding data layers

# USE_OPENCV := 0

# USE_LEVELDB := 0

# USE_LMDB := 0

 

# uncomment to allow MDB_NOLOCK when readingLMDB files (only if necessary)

#     Youshould not set this flag if you will be reading LMDBs with any

#     possibilityof simultaneous read and write

# ALLOW_LMDB_NOLOCK := 1

 

# Uncomment if you're using OpenCV 3

 OPENCV_VERSION := 3

 

# To customize your choice of compiler,uncomment and set the following.

# N.B. the default for Linux is g++ and thedefault for OSX is clang++

# CUSTOM_CXX := g++

 

# CUDA directory contains bin/ and lib/directories that we need.

CUDA_DIR := /usr/local/cuda

# On Ubuntu 14.04, if cuda tools are installedvia

# "sudo apt-get installnvidia-cuda-toolkit" then use this instead:

# CUDA_DIR := /usr

 

# CUDA architecture setting: going with all ofthem.

# For CUDA < 6.0, comment the *_50 linesfor compatibility.

CUDA_ARCH := -gencode arch=compute_20,code=sm_20\

              -gencodearch=compute_20,code=sm_21 \

              -gencodearch=compute_30,code=sm_30 \

              -gencodearch=compute_35,code=sm_35 \

              -gencodearch=compute_50,code=sm_50 \

              -gencodearch=compute_50,code=compute_50

 

# BLAS choice:

# atlas for ATLAS (default)

# mkl for MKL

# open for OpenBlas

BLAS := atlas

# Custom (MKL/ATLAS/OpenBLAS) include and libdirectories.

# Leave commented to accept the defaults foryour choice of BLAS

# (which should work)!

# BLAS_INCLUDE := /path/to/your/blas

# BLAS_LIB := /path/to/your/blas

 

# Homebrew puts openblas in a directory thatis not on the standard search path

# BLAS_INCLUDE := $(shell brew --prefixopenblas)/include

# BLAS_LIB := $(shell brew --prefixopenblas)/lib

 

# This is required only if you will compilethe matlab interface.

# MATLAB directory should contain the mexbinary in /bin.

MATLAB_DIR := /usr/local/MATLAB/R2015b

#MATLAB_DIR := /Applications/MATLAB_R2012b.app

 

# NOTE: this is required only if you willcompile the python interface.

# We need to be able to find Python.h andnumpy/arrayobject.h.

PYTHON_INCLUDE := /usr/include/python2.7 \

              /usr/local/lib/python2.7/dist-packages/numpy/core/include

# Anaconda Python distribution is quitepopular. Include path:

# Verify anaconda location, sometimes it's inroot.

# ANACONDA_HOME := $(HOME)/anaconda

# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \

              #$(ANACONDA_HOME)/include/python2.7 \

              #$(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \

 

# Uncomment to use Python 3 (default is Python2)

# PYTHON_LIBRARIES := boost_python3 python3.5m

# PYTHON_INCLUDE := /usr/include/python3.5m \

#                /usr/lib/python3.5/dist-packages/numpy/core/include

 

# We need to be able to find libpythonX.X.soor .dylib.

PYTHON_LIB := /usr/lib

# PYTHON_LIB := $(ANACONDA_HOME)/lib

 

# Homebrew installs numpy in a non standardpath (keg only)

# PYTHON_INCLUDE += $(dir $(shell python -c'import numpy.core; print(numpy.core.__file__)'))/include

# PYTHON_LIB += $(shell brew --prefixnumpy)/lib

 

# Uncomment to support layers written inPython (will link against Python libs)

# WITH_PYTHON_LAYER := 1

 

# Whatever else you find you need goes here.

INCLUDE_DIRS := $(PYTHON_INCLUDE)/usr/local/include

LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib/usr/lib

 

# If Homebrew is installed at a non standardlocation (for example your home directory) and you use it for generaldependencies

# INCLUDE_DIRS += $(shell brew--prefix)/include

# LIBRARY_DIRS += $(shell brew --prefix)/lib

 

# Uncomment to use `pkg-config` to specifyOpenCV library paths.

# (Usually not necessary -- OpenCV librariesare normally installed in one of the above $LIBRARY_DIRS.)

# USE_PKG_CONFIG := 1

 

# N.B. both build and distribute dirs arecleared on `make clean`

BUILD_DIR := build

DISTRIBUTE_DIR := distribute

 

# Uncomment for debugging. Does not work onOSX due to https://github.com/BVLC/caffe/issues/171

# DEBUG := 1

 

# The ID of the GPU that 'make runtest' willuse to run unit tests.

TEST_GPUID := 0

 

# enable pretty build (comment to see fullcommands)

Q ?= @

 

保存并退出,在caffe文件夹下配置并编译

cdcaffe

mkdirbuild

cdbuild

cmake..

make  all -j16

maketest

makeruntest

makepycaffe(若要使用python接口)

makematcaffe(若要使用matlab接口)

 

9、安装matlab

      我安装的是MATLAB2015b,百度搜索有许多都是安装MATLAB2014a的,会更稳定,但是只支持gcc 4.7及以下,由于上次安装gcc5.3之后无法切换导致了一系列错误,我决定先安装2015试试,可参照http://blog.csdn.net/lcx543576178/article/details/51376008

 

sudo mkdir/media/matlab

cd xxxxxx(matlab镜像所在文件夹)

sudo mount -oR2015b_glnxa64.iso /media/matlab

cd/media/matlab

./install

#注意:选择不联网安装,输入crack文件夹中的序列号。然后要使用matlab的接口需要在caffe文件夹下修改Makefile.Configuration,将use matlab前的#注释符去掉。

 

安装完成后激活

cd/usr/local/MATLAB/R2015b/bin(默认安装目录)

sudo ./matlab  #选择不联网,利用crack文件夹下lisence文件激活。激活完成后将crack文件夹下的glnxa64文件夹下的文件copy到   /usr/local/MATLAB/R2015b/bin/glnxa64

 

运行:

cd/usr/local/MATLAB/R2015b/bin

./matlab

 

创建快捷方式参照:http://www.linuxidc.com/Linux/2011-01/31632.htm

 

遇到的问题

 

1、循环登录

     有时候重启电脑之后进入图形界面输入用户密码却怎么都进不了桌面,又重新弹出登录界面。

      解决办法:重装显卡驱动

      首先,需要事先在NVIDIA官网下载与自己显卡对应的图形驱动(cuda对显卡有一定的要求,基本上得是n卡才能保证一定跑的起来),保存在电脑某个自己找得到的地方。

       遭遇循环登录时,ctrl+f1进入shell主界面,执行以下操作:

 

        cd 存放驱动的文件夹

        sudo service lightdm stop  #关闭图形界面

        sudo sh NVIDIA_Linux-xxxxxxx.ru    #选择accept、continue 、OK等

        sudo service lightdm start

       

 

2、查询不到nvcc

    装好cuda后利用nvcc –version查询nvcc版本,出现以下提示信息:

Theprogram 'nvcc' is currently not installed. You can install it by typing:

sudoapt-get install nvidia-cuda-toolkit

     注意:不要执行提示中的命令

     执行sudoapt-get install nvidia-cuda-toolkit后系统会自动安装某个低版本的cuda,当时我手贱,这么试了一下,就装上了cuda5.5,而且找不到对应文件夹,没法删除。

 

3、键盘错位

     由于在安装系统的时候选择了enlish(UK),键盘布局变成了英式,|打出来是#,~打出来是个不知名符号,某些指令也无法打出来了,特别糟心。

     解决方法:配置fcitx

     参照方案http://www.linuxdiyf.com/linux/16832.html

    关键是我按照上述网页的方法修改了text input也没有用。经多方折腾,发现原来是没有修改fcitx的配置。我使用的搜狗输入法是建立在在fcitx基础上的。在终端输入

    

     fcitx-config-gtk3

 

     在当前选项中删除english(uk),添加english(us)

 

4、caffemake出错:/bin/bash: aclocal-1.14: command not found

    解决方法:sudo apt-get installautomake

 

5、apt-get update或导入软件源时出出错:NO_PUBKEY xxxxxxxxxxxxx

     安装某些软件时,需要在安装之前导入软件源,如以安装gcc 时提到的sudoadd-apt-repository ppa:ubuntu-toolchain-r/test。有时候会出现如题所示错误

    解决方法:导入该秘钥

    法1、sudo apt-key adv –recv-keys –keyserver keyserver.ubuntu.comxxxxxxxx(提示缺少的秘钥)

     法2、sudo gpg –export –amor xxxxxxxx(秘钥后8位) | sudo apt-key add-

   

   注:若法1出错,出错信息显示能够链接但无法导入,可能是因为端口不对。将网站改为hkp://keyserver.ubuntu.com:80

 

 

6version GLIBXX_3.4.21 not defined in file libstdc++.so.6

    解决方法:修改链接文件

    sudo gedit /etc/ls.so.conf.d/libc.conf

    将 /usr/local/lib改为 /usr/local/lib64

 

7、caffe make 出错: libprotobuf.so.11 :cannotopen shred object file : no such file or directory

      locate libprotobuf.so.11

     发现 /usr/local/lib下有该文件而/usr/local/lib下没有

     解决方法:修改链接文件

     sudo gedit /etc/ld.so.conf

     添加下面一行

     /include/usr/local/lib64

 

8、sudo apt-get update出错:E:could not get lock xxxxxx

     解决方法:sudodpkg –configure -a

 

9、sudo apt-get update出错:Err: http://exoas.ubuntu.comtrustly Inrelease

    解决方法:删除不必要的软件源

     法1、从软件和更新(software & updates)中删除不必要的软件源

     法2、sudo gedit /etc/apt/source.list

             找到以上出错的源,在前加#注释掉

              保存并退出,然后执行sudo ldconfig

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值