zoukankan      html  css  js  c++  java
  • Ubuntu16.04+Cuda8.0+1080ti+caffe+免OpenCV3.2.0+faster-rCNN教程

    一、事先声明:
    1、Ubuntu版本:Ubuntu使用的是16.04。而不是16.04.1或16.04.2,这三个是有区别的。笔者曾有过这样的经历,Git上一个SLAM地图构建程序在Ubuntu14.04.3上可以正常make与工作,而14.04.4却一塌Error。。。

    可自己在Google搜索关键字“Ubuntu16.04.1”做“引子”找到历史版本,第一个就是。在此我们放出网址:

    http://old-releases.ubuntu.com/releases/16.04.1/

    问:有两个“64-bit PC (AMD64) desktop image”怎么办?那个才是16.04?
    答:点进去看看ISO前缀名称!

    2、为什么免安装OpenCV?很简单,因为Ubuntu自带!但不是OpenCV3,而是OpenCV 2.x.x.x,具体是多少我忘了,你可用命令

    [plain] view plain copy
     
    1. pkg-config --modversion opencv  

    查询一下,faster-rcnn用Ubuntu自带的OpenCV2的即可正常运行。如果您非要使用CV3,这里也给出参考教程。要相信OpenCV3不是三四行shell就能装好的,不信你去搜搜专门安装CV3的博客。OpenCV3.2.0安装链接如下
    https://www.linuxhint.com/how-to-install-opencv-on-ubuntu/

    二、软件版本:

    Ubuntu16.04

    Cuda8.0

    1080ti驱动

    OpenCV3.2.0

    cuDNN5.1 (5.1.10)

    glog-0.3.3.tar.gz

    注:以上这些都可以事先下载好。

    注意:安装完Ubuntu后记得关闭“自动更新”。笔者装机完,正常使用两天后,出现了ubuntu反复登录桌面的问题。我是重装了Unity,也装了GDM。但愿你不会出现这类问题,如果出现了,下面给出解决链接。

    http://www.linuxidc.com/Linux/2011-07/39491.htm

    http://forum.ubuntu.org.cn/viewtopic.PHP?t=460910

    三、安装Caffe参考:

    1、主要参考:

    迷途de小狼:

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

    2、辅助参考:

    http://www.jianshu.com/p/69a10d0a24b9

    http://blog.csdn.Net/yan_song_/article/details/53154611

    http://www.linuxidc.com/Linux/2016-09/135016.htm

    http://blog.csdn.net/zhangzhenyuancs/article/details/52261004

    3、声明与建议:

    在此感谢几位网友的博客,正是参考了几位大神的博客才有我的成功安装。如有版权问题,请联系我,谢谢。

    另外就是给要安装的朋友们给两个建议,自己搜索、或从上面的参考中至少选择三四篇文章通篇阅读一下,形成适合自己的安装思路。别人(包括本Blog)的环境都可能和屏幕前的你有所出入,所以要有所取舍。

    四、安装Caffe步骤:

    1、安装Ubuntu16.04

    120G SSD:

    /boot 400MB

    / SSD剩余所有

    swap 内存两倍空间(心疼SSD的可放在2T机械)

    2T

    /home

    2、安装1080ti驱动

    [plain] view plain copy
     
    1. Ctrl+alt+F1//进入字符界面  
    2. sudo service lightdm stop //关闭lightdm登录管理器   
    3. sudo chmod 755 NVIDIA-Linux-x86_64-378.13.run  //获取权限    
    4. sudo ./NVIDIA-Linux-x86_64-378.13.run  //安装驱动  

    Accept 

    Continue installation 

    安装完成之后

    sudo service lightdm start

    3、安装Cuda8.0

    [plain] view plain copy
     
    1. sudo sh ./cuda_8.0.61_375.26_linux-run  

    进入安装命令行
    ---Do you accept the previously read EULA?
    accept/decline/quit: accept
    ---Install NVIDIA Accelerated Graphics Driver for Linux-x86_64361.62? 
    (y)es/(n)o/(q)uit: n
    ---Install the CUDA 8.0 Toolkit? 
    (y)es/(n)o/(q)uit: y
    ---Enter Toolkit Location 
    [ default is /usr/local/cuda-8.0 ]:回车
    ---Do you want to install a symbolic link at /usr/local/cuda?
    (y)es/(n)o/(q)uit: y
    ---Install the CUDA 8.0 Samples? 
    (y)es/(n)o/(q)uit: y
    ---Enter CUDA Samples Location 
    [ default is /home/duan ]:回车

    4、安装OpenCV(可跳过,Ubuntu默认安装cv2):

    见第一章网址,不用修改什么源文件。

    注:如果你是4/8线程可用下代码加速编译:

    [plain] view plain copy
     
    1. make -j4       #四核运算  

    5、安装依赖项:

    1)Google Logging Library(glog),下载地址:https://code.google.com/p/google-glog/,然后解压安装:
    $ tar zxvf glog-0.3.3.tar.gz
    $ cd glog-0.3.3 
    $./configure
    $ make
    $ sudo make install
    如果没有权限就chmod a+x glog-0.3.3 -R , 或者索性 chmod 777 glog-0.3.3 -R 。


    2)其他依赖项,确保都成功

    $ sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler protobuf-c-compiler protobuf-compiler

    6、安装Caffe,并用MNIST数据集测试

    1)安装pycaffe必须的一些依赖项:

    sudo apt-get install -y Python-numpy python-scipy python-matplotlib python-sklearn python-skimage python-h5py python-protobuf python-leveldb python-networkx python-nose python-pandas python-gflags cython ipython 

    2)安装配置nVidia cuDNN 加速Caffe模型运算

    [plain] view plain copy
     
    1. 1. $ sudo cp include/cudnn.h /usr/local/include    
    2. 2. $ sudo cp lib64/libcudnn.* /usr/local/lib  
    3. 3. $ sudo ln -sf /usr/local/lib/libcudnn.so.5.1.10 /usr/local/lib/libcudnn.so.5    
    4. 4. $ sudo ln -sf /usr/local/lib/libcudnn.so.5 /usr/local/lib/libcudnn.so    
    5. 5. $ sudo ldconfig -v    

    注:大家根据自己的cuDNN版本修改;如果懒于敲目录,可在Unity文件管理器下将文件夹拖入终端;终端下的“粘贴”快捷键:Ctrl+Shift+v。

    3)切换到Caffe-master的文件夹,生成Makefile.config配置文件,执行:

    [plain] view plain copy
     
    1. $ cp Makefile.config.example Makefile.config  


    4)配置Makefile.config文件

    a.去掉“USE_CUDNN := 1”前面的#

    b.根据前面自己的需求,选择性去掉“OPENCV_VERSION :=3”前面的#

    c.配置一些引用文件(增加部分主要是解决新版本下,HDF5的路径问题)
    INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/lib/x86_64-linux-gnu/hdf5/serial/include
    LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial

    下面贴出我的Makefile.config文件

    [plain] view plain copy
     
    1. ## Refer to http://caffe.berkeleyvision.org/installation.html  
    2. # Contributions simplifying and improving our build system are welcome!  
    3.   
    4. # cuDNN acceleration switch (uncomment to build with cuDNN).  
    5.  USE_CUDNN := 1  
    6.   
    7. # CPU-only switch (uncomment to build without GPU support).  
    8. # CPU_ONLY := 1  
    9.   
    10. # uncomment to disable IO dependencies and corresponding data layers  
    11. # USE_OPENCV := 0  
    12. # USE_LEVELDB := 0  
    13. # USE_LMDB := 0  
    14.   
    15. # uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)  
    16. #   You should not set this flag if you will be reading LMDBs with any  
    17. #   possibility of simultaneous read and write  
    18. # ALLOW_LMDB_NOLOCK := 1  
    19.   
    20. # Uncomment if you're using OpenCV 3  
    21. # OPENCV_VERSION := 3  
    22.   
    23. # To customize your choice of compiler, uncomment and set the following.  
    24. # N.B. the default for Linux is g++ and the default for OSX is clang++  
    25. # CUSTOM_CXX := g++  
    26.   
    27. # CUDA directory contains bin/ and lib/ directories that we need.  
    28. CUDA_DIR := /usr/local/cuda  
    29. # On Ubuntu 14.04, if cuda tools are installed via  
    30. # "sudo apt-get install nvidia-cuda-toolkit" then use this instead:  
    31. # CUDA_DIR := /usr  
    32.   
    33. # CUDA architecture setting: going with all of them.  
    34. # For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.  
    35. # For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.  
    36. CUDA_ARCH := -gencode arch=compute_20,code=sm_20   
    37.         -gencode arch=compute_20,code=sm_21   
    38.         -gencode arch=compute_30,code=sm_30   
    39.         -gencode arch=compute_35,code=sm_35   
    40.         -gencode arch=compute_50,code=sm_50   
    41.         -gencode arch=compute_52,code=sm_52   
    42.         -gencode arch=compute_60,code=sm_60   
    43.         -gencode arch=compute_61,code=sm_61   
    44.         -gencode arch=compute_61,code=compute_61  
    45.   
    46. # BLAS choice:  
    47. # atlas for ATLAS (default)  
    48. # mkl for MKL  
    49. # open for OpenBlas  
    50. BLAS := atlas  
    51. # Custom (MKL/ATLAS/OpenBLAS) include and lib directories.  
    52. # Leave commented to accept the defaults for your choice of BLAS  
    53. # (which should work)!  
    54. # BLAS_INCLUDE := /path/to/your/blas  
    55. # BLAS_LIB := /path/to/your/blas  
    56.   
    57. # Homebrew puts openblas in a directory that is not on the standard search path  
    58. # BLAS_INCLUDE := $(shell brew --prefix openblas)/include  
    59. # BLAS_LIB := $(shell brew --prefix openblas)/lib  
    60.   
    61. # This is required only if you will compile the matlab interface.  
    62. # MATLAB directory should contain the mex binary in /bin.  
    63. # MATLAB_DIR := /usr/local  
    64. # MATLAB_DIR := /Applications/MATLAB_R2012b.app  
    65.   
    66. # NOTE: this is required only if you will compile the python interface.  
    67. # We need to be able to find Python.h and numpy/arrayobject.h.  
    68. PYTHON_INCLUDE := /usr/include/python2.7   
    69.         /usr/lib/python2.7/dist-packages/numpy/core/include  
    70. # Anaconda Python distribution is quite popular. Include path:  
    71. # Verify anaconda location, sometimes it's in root.  
    72. # ANACONDA_HOME := $(HOME)/anaconda  
    73. # PYTHON_INCLUDE := $(ANACONDA_HOME)/include   
    74.         # $(ANACONDA_HOME)/include/python2.7   
    75.         # $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include  
    76.   
    77. # Uncomment to use Python 3 (default is Python 2)  
    78. # PYTHON_LIBRARIES := boost_python3 python3.5m  
    79. # PYTHON_INCLUDE := /usr/include/python3.5m   
    80. #                 /usr/lib/python3.5/dist-packages/numpy/core/include  
    81.   
    82. # We need to be able to find libpythonX.X.so or .dylib.  
    83. PYTHON_LIB := /usr/lib  
    84. # PYTHON_LIB := $(ANACONDA_HOME)/lib  
    85.   
    86. # Homebrew installs numpy in a non standard path (keg only)  
    87. # PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include  
    88. # PYTHON_LIB += $(shell brew --prefix numpy)/lib  
    89.   
    90. # Uncomment to support layers written in Python (will link against Python libs)  
    91. # WITH_PYTHON_LAYER := 1  
    92.   
    93. # Whatever else you find you need goes here.  
    94. INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/lib/x86_64-linux-gnu/hdf5/serial/include  
    95. LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial  
    96.   
    97. # If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies  
    98. # INCLUDE_DIRS += $(shell brew --prefix)/include  
    99. # LIBRARY_DIRS += $(shell brew --prefix)/lib  
    100.   
    101. # NCCL acceleration switch (uncomment to build with NCCL)  
    102. # https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)  
    103. # USE_NCCL := 1  
    104.   
    105. # Uncomment to use `pkg-config` to specify OpenCV library paths.  
    106. # (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)  
    107. # USE_PKG_CONFIG := 1  
    108.   
    109. # N.B. both build and distribute dirs are cleared on `make clean`  
    110. BUILD_DIR := build  
    111. DISTRIBUTE_DIR := distribute  
    112.   
    113. # Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171  
    114. # DEBUG := 1  
    115.   
    116. # The ID of the GPU that 'make runtest' will use to run unit tests.  
    117. TEST_GPUID := 0  
    118.   
    119. # enable pretty build (comment to see full commands)  
    120. Q ?= @  



    5)编译caffe-master!!!"-j4"是使用CPU的多核进行编译,可以极大地加速编译的速度,建议使用。

    注:下面的make命令适当的时候加上sudo,建议都已super do来运行。

    [plain] view plain copy
     
    1. $ make all -j4  
    2. $ make test -j4   
    3. $ make runtest -j4  

    期间会遇到下面的问题:

    问题:mkl_alternate.hpp:14:19 fatal error: cblas.h: 没有那个文件或目录

    解决:https://github.com/BVLC/caffe/issues/3599

    [plain] view plain copy
     
    1. sudo apt-get install libopenblas-dev  

    问题:找不到 -lablas、-latlas

    解决:

    [plain] view plain copy
     
    1. sudo apt-get install libatlas-base-dev  

    可能问题:.build_release/lib/libcaffe.so.1.0.0 Error 1 /usr/bin/ld: 找不到 -lopencv_imgcodecs

    解决:你没有安装好CV3,可选择加上b的井号,或参考

    https://my.oschina.net/peterlie/blog/661994

    http://blog.csdn.net/foolsnowman/article/details/50532226

    问题:caffe libcudart.so.8.0 cannot open shared object file no such file or directory

    解决:https://github.com/NVIDIA/DIGITS/issues/8

    [plain] view plain copy
     
    1. sudo ldconfig /usr/local/cuda/lib64  

    问题:nvcc warring: the 'compute_20', 'sm_20', and 'sm_21'

    解决:我是不理会,不影响使用,想看一眼的可参考以下网址:

    http://www.itwendao.com/article/detail/214390.html


    6)编译Python和Matlab用到的caffe文件

    [plain] view plain copy
     
    1. $ make pycaffe -j4  


    7)测试

    打开example -> MNIST -> Readme.md

    按照最前面,cd到Caffe根目录,运行第一页的两个命令,进行下载和格式转换(不超过30MB的下载量)

    再运行最下面的命令,Training,看命令行盖楼。。。

    五、安装faster-r-cnn参考

    bit_hammer大神:

    http://blog.csdn.net/u011635764/article/details/52831167

    cuDNN v5、v5.1的问题

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

    大家按照bit_hammer大神的步骤安装就好,关于cuDNN v5.1的处理,两篇文章都一样的。

    注:faster-r-cnn一定要从Git Clone,Download ZIP不全。

    六、测试faster-r-cnn

    从百度云盘下载训练好的模型:

    VGG16_faster_rcnn_final.caffemodel (548.3MB)

    2F_faster_rcnn_final.caffemodel (237.2MB)

    将上述两个文件存放于:

    py-faster-rcnn/data/faster_rcnn_models/

    下,即可运行步骤五中的Demo。

    转自http://blog.csdn.net/dylll321/article/details/72784159

  • 相关阅读:
    分享一个 @user 前端插件
    .net 的一个分词系统(jieba中文分词的.NET版本:jieba.NET)
    InvokeMember 使用(转http://blog.csdn.net/gooer/article/details/2927113)
    C#反射机制(转自Binfire博客)
    MVC中使用AuthorizeAttribute做身份验证操作
    javascript日期操作详解
    精通 JS正则表达式
    JavaScript 正则表达式
    Js获取当前日期时间及其它操作
    Django 模板中 变量 过滤器的使用方法
  • 原文地址:https://www.cnblogs.com/JZ-Ser/p/6922701.html
Copyright © 2011-2022 走看看