2015.08.17 Ubuntu 14.04+cuda 7.5+caffe安装配置

前端之家收集整理的这篇文章主要介绍了2015.08.17 Ubuntu 14.04+cuda 7.5+caffe安装配置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

2016.06.10 update cuda 7.5 and cudnn v5

2015.10.23更新:修改了一些地方,身边很多人按这个流程安装,完全可以安装

折腾了两个星期的caffe,windows和ubuntu下都安装成功了。其中windows的安装配置参考官网推荐的那个blog,后来发现那个版本的caffe太老,和现在的不兼容,一些关键字都不一样,果断回到Linux下。这里记录一下我的安装配置流程。

电脑配置:

ubuntu 14.0464bit

8G 内存

GTX650显卡


软件版本:

CUDA 7.0

caffe 当天从github下载的版本


安装ubuntu的过程省略,建议安装后关闭自动更新,上一次安装caffe后用的很好,结果有一天晚上没关电脑,自己半夜更新了显卡驱动,然后...


caffe的安装流程主要参考这个blog,稍有改动:Caffe + Ubuntu 14.04 64bit + CUDA 6.5 配置说明


Caffe 安装配置步骤:


1, 安装开发所需的依赖包

  1. sudoapt-getinstallbuild-essential#basicrequirement
  2. sudoapt-getinstalllibprotobuf-devlibleveldb-devlibsnappy-devlibopencv-devlibboost-all-devlibhdf5-serial-devlibgflags-devlibgoogle-glog-devliblmdb-devprotobuf-compiler#requiredbycaffe


Before install CUDA 7.5,you need update gcc 4.8+ to gcc 4.9+

reference:update gcc/g++

2,安装CUDA 7.5

验证过程省略,按照官方文档自己操作吧(遇到问题首先要看官方文档啊,血泪教训)

安装CUDA有两种方法

离线.run安装:从官网下载对应版本的.run安装包安装,安装过程挺复杂,尝试过几次没成功,遂放弃。

在离线.deb安装:deb安装分离线和在线,我都尝试过都安装成功了,官网下载地址


安装之前请先进行md5校验,确保下载的安装包完整

切换到下载的deb所在目录,执行下边的命令
  1. sudodpkg-icuda-repo-<distro>_<version>_<architecture>.deb
  2. sudoapt-getupdate
  3. sudoapt-getinstallcuda
然后重启电脑:sudo reboot
NOTE:装不成功卸了多来几遍,总会成的

3,安装cuDNN
下载cudnn-7.5-linux-x64-v5.0-ga.tgz,官网申请不到,网上自己找的,就不给地址了。
  1. tar-zxvfcudnn-7.5-linux-x64-v5.0-ga.tgz
  2. cdcuda
  3. sudocplib/lib*/usr/local/cuda/lib64/
  4. sudocpinclude/cudnn.h/usr/local/cuda/include/
更新软连接
cd /usr/local/cuda/lib64/
sudo chmod +r libcudnn.so.5.0.5
sudo ln -sf libcudnn.so.5.0.5 libcudnn.so.5
sudo ln -sf libcudnn.so.5 libcudnn.so
sudo ldconfig
4,设置环境变量
在/etc/profile中添加CUDA环境变量
sudo gedit /etc/profile
  1. PATH=/usr/local/cuda/bin:$PATH
  2. exportPATH
保存后,执行下列命令,使环境变量立即生效
  1. source/etc/profile
同时需要添加lib库路径: 在 /etc/ld.so.conf.d/加入文件 cuda.conf,内容如下
  1. /usr/local/cuda/lib64
保存后,执行下列命令使之立刻生效
  1. sudoldconfig

5,安装CUDA SAMPLE
进入/usr/local/cuda/samples,执行下列命令来build samples
  1. sudomakeall-j4
整个过程大概10分钟左右,全部编译完成后, 进入 samples/bin/x86_64/linux/release,运行deviceQuery
  1. ./deviceQuery
如果出现显卡信息, 则驱动及显卡安装成功:
  1. ./deviceQueryStarting...
  2. CUDADeviceQuery(RuntimeAPI)version(CUDARTstaticlinking)
  3. Detected1CUDACapabledevice(s)
  4. Device0:"GeForceGTX670"
  5. CUDADriverVersion/RuntimeVersion6.5/6.5
  6. CUDACapabilityMajor/Minorversionnumber:3.0
  7. Totalamountofglobalmemory:4095MBytes(4294246400bytes)
  8. (7)Multiprocessors,(192)CUDACores/MP:1344CUDACores
  9. GPUClockrate:1098MHz(1.10GHz)
  10. MemoryClockrate:3105Mhz
  11. MemoryBusWidth:256-bit
  12. L2CacheSize:524288bytes
  13. MaximumTextureDimensionSize(x,y,z)1D=(65536),2D=(65536,65536),3D=(4096,4096,4096)
  14. MaximumLayered1DTextureSize,(num)layers1D=(16384),2048layers
  15. MaximumLayered2DTextureSize,(num)layers2D=(16384,16384),2048layers
  16. Totalamountofconstantmemory:65536bytes
  17. Totalamountofsharedmemoryperblock:49152bytes
  18. Totalnumberofregistersavailableperblock:65536
  19. Warpsize:32
  20. Maximumnumberofthreadspermultiprocessor:2048
  21. Maximumnumberofthreadsperblock:1024
  22. Maxdimensionsizeofathreadblock(x,z):(1024,1024,64)
  23. Maxdimensionsizeofagridsize(x,z):(2147483647,65535,65535)
  24. Maximummemorypitch:2147483647bytes
  25. Texturealignment:512bytes
  26. Concurrentcopyandkernelexecution:Yeswith1copyengine(s)
  27. Runtimelimitonkernels:Yes
  28. IntegratedGPUsharingHostMemory:No
  29. Supporthostpage-lockedmemorymapping:Yes
  30. AlignmentrequirementforSurfaces:Yes
  31. DevicehasECCsupport:Disabled
  32. DevicesupportsUnifiedAddressing(UVA):Yes
  33. DevicePCIBusID/PCIlocationID:1/0
  34. ComputeMode:
  35. <Default(multiplehostthreadscanuse::cudaSetDevice()withdevicesimultaneously)>
  36. deviceQuery,CUDADriver=CUDART,CUDADriverVersion=6.5,CUDARuntimeVersion=6.5,NumDevs=1,Device0=GeForceGTX670
  37. Result=PASS
NOTE:上边的显卡信息是从别的地方拷过来的,我的GTX650显卡不是这些信息,如果没有这些信息,那肯定是安装不成功,找原因吧!

6,安装Intel MKL 或Atlas
我没有MKL,装的Atlas
安装命令:
  1. sudoapt-getinstalllibatlas-base-dev

7,安装OpenCV
我安装的是2.4.10
1)下载 安装脚本
2)进入目录 Install-OpenCV/Ubuntu/2.4
3)执行脚本
  1. sudosh./opencv2_4_10.sh

8,安装Caffe所需要的Python环境
按caffe官网的推荐使用Anaconda
去Anaconda官网下载安装包
切换到文件所在目录,执行
  1. bashAnaconda-2.3.0-Linux-x86_64.s<em>h</em>
NOTE:后边的文件名按自己下的版本号更改,整个安装过程请选择默认

8.1,添加Anaconda Library Path
在/etc/ld.so.conf最后加入以下路径,并没有出现重启不能进入界面的问题( NOTE:下边的username要替换)
  1. /home/username/anaconda/lib
在~/.bashrc最后添加下边路径
  1. exportLD_LIBRARY_PATH="/home/username/anaconda/lib:$LD_LIBRARY_PATH"



9,安装python依赖库
去caffe的github下载caffe源码包
进入caffe-master下的python目录
执行如下命令
  1. forreqin$(catrequirements.txt);dopipinstall$req;done

10,编译Caffe
终于来到这里了
进入caffe-master目录,复制一份Makefile.config.examples
  1. cpMakefile.config.exampleMakefile.config
修改其中的一些路径,如果前边和我说的一致,都选默认路径的话,那么配置文件应该张这个样子
  1. ##Refertohttp://caffe.berkeleyvision.org/installation.html
  2. #Contributionssimplifyingandimprovingourbuildsystemarewelcome!
  3. #cuDNNaccelerationswitch(uncommenttobuildwithcuDNN).
  4. USE_CUDNN:=1
  5. #cpu-onlyswitch(uncommenttobuildwithoutGPUsupport).
  6. #cpu_ONLY:=1
  7. #Tocustomizeyourchoiceofcompiler,uncommentandsetthefollowing.
  8. #N.B.thedefaultforLinuxisg++andthedefaultforOSXisclang++
  9. #CUSTOM_CXX:=g++
  10. #CUDAdirectorycontainsbin/andlib/directoriesthatweneed.
  11. CUDA_DIR:=/usr/local/cuda
  12. #OnUbuntu14.04,ifcudatoolsareinstalledvia
  13. #"sudoapt-getinstallnvidia-cuda-toolkit"thenusethisinstead:
  14. #CUDA_DIR:=/usr
  15. #CUDAarchitecturesetting:goingwithallofthem.
  16. #ForCUDA<6.0,commentthe*_50linesforcompatibility.
  17. CUDA_ARCH:=-gencodearch=compute_20,code=sm_20\
  18. -gencodearch=compute_20,code=sm_21\
  19. -gencodearch=compute_30,code=sm_30\
  20. -gencodearch=compute_35,code=sm_35\
  21. -gencodearch=compute_50,code=sm_50\
  22. -gencodearch=compute_50,code=compute_50
  23. #BLASchoice:
  24. #atlasforATLAS(default)
  25. #mklforMKL
  26. #openforOpenBlas
  27. BLAS:=atlas
  28. #Custom(MKL/ATLAS/OpenBLAS)includeandlibdirectories.
  29. #LeavecommentedtoacceptthedefaultsforyourchoiceofBLAS
  30. #(whichshouldwork)!
  31. #BLAS_INCLUDE:=/path/to/your/blas
  32. #BLAS_LIB:=/path/to/your/blas
  33. #Homebrewputsopenblasinadirectorythatisnotonthestandardsearchpath
  34. #BLAS_INCLUDE:=$(shellbrew--prefixopenblas)/include
  35. #BLAS_LIB:=$(shellbrew--prefixopenblas)/lib
  36. #Thisisrequiredonlyifyouwillcompilethematlabinterface.
  37. #MATLABdirectoryshouldcontainthemexbinaryin/bin.
  38. #MATLAB_DIR:=/usr/local
  39. #MATLAB_DIR:=/Applications/MATLAB_R2012b.app
  40. #NOTE:thisisrequiredonlyifyouwillcompilethepythoninterface.
  41. #WeneedtobeabletofindPython.handnumpy/arrayobject.h.
  42. #PYTHON_INCLUDE:=/usr/include/python2.7\
  43. /usr/lib/python2.7/dist-packages/numpy/core/include
  44. #AnacondaPythondistributionisquitepopular.Includepath:
  45. #Verifyanacondalocation,sometimesit'sinroot.
  46. ANACONDA_HOME:=$(HOME)/anaconda
  47. PYTHON_INCLUDE:=$(ANACONDA_HOME)/include\
  48. $(ANACONDA_HOME)/include/python2.7\
  49. $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include\
  50. #WeneedtobeabletofindlibpythonX.X.soor.dylib.
  51. #PYTHON_LIB:=/usr/lib
  52. PYTHON_LIB:=$(ANACONDA_HOME)/lib
  53. #Homebrewinstallsnumpyinanonstandardpath(kegonly)
  54. #PYTHON_INCLUDE+=$(dir$(shellpython-c'importnumpy.core;print(numpy.core.__file__)'))/include
  55. #PYTHON_LIB+=$(shellbrew--prefixnumpy)/lib
  56. #UncommenttosupportlayerswritteninPython(willlinkagainstPythonlibs)
  57. #WITH_PYTHON_LAYER:=1
  58. #Whateverelseyoufindyouneedgoeshere.
  59. INCLUDE_DIRS:=$(PYTHON_INCLUDE)/usr/local/include
  60. LIBRARY_DIRS:=$(PYTHON_LIB)/usr/local/lib/usr/lib
  61. #IfHomebrewisinstalledatanonstandardlocation(forexampleyourhomedirectory)andyouuseitforgeneraldependencies
  62. #INCLUDE_DIRS+=$(shellbrew--prefix)/include
  63. #LIBRARY_DIRS+=$(shellbrew--prefix)/lib
  64. #Uncommenttouse`pkg-config`tospecifyOpenCVlibrarypaths.
  65. #(Usuallynotnecessary--OpenCVlibrariesarenormallyinstalledinoneoftheabove$LIBRARY_DIRS.)
  66. #USE_PKG_CONFIG:=1
  67. BUILD_DIR:=build
  68. DISTRIBUTE_DIR:=distribute
  69. #Uncommentfordebugging.DoesnotworkonOSXduetohttps://github.com/BVLC/caffe/issues/171
  70. #DEBUG:=1
  71. #TheIDoftheGPUthat'makeruntest'willusetorununittests.
  72. TEST_GPUID:=0
  73. #enableprettybuild(commenttoseefullcommands)
  74. Q?=@

保存退出
编译
  1. makeall-j4
  2. maketest
  3. makeruntest

11,编译Python wrapper

  1. makepycaffe
到这里就基本结束了,跑个自带的例子测试一下吧! NOTE:以上是我在自己PC上的安装步骤,因软件版本不同,硬件环境不同,按照以上方式可能出现错误,请耐心查找错误,欢迎留言 原文链接:https://www.f2er.com/ubuntu/351781.html

猜你在找的Ubuntu相关文章