zoukankan      html  css  js  c++  java
  • 【神经网络与深度学习】转-caffe安装吐血总结

    这周安装了caffe的windows版本和Linux版本,依赖关系太多,如果系统选对了,安装起来很easy,选错了,就会遇见各种坑。

    1.操作系统最好使用ubuntu desktop 14.04 64位。

    我试用的操作系统版本比较多,以下介绍一下操作系统的坑:

    ubuntu server 14.04  64位,部分u盘启动工具不支持,安装一半会报错找不到cdrom。

    ubuntu server 15.10  64位,gcc版本太高,编译OpenCV时调用cudnn时有问题,替换低版本无效,未查到原因。

    ubuntu server 16.04   64位,cudnn没有相应版本,编译cudnn是报错。

    opensuse,下载依赖库很麻烦,很多依赖库都没有,建议不要使用。


    2.本人一直是做服务器开发,习惯了命令行(这也是一开始选择server版本遇到各种坑的原因),而且桌面占用资源太多,所以要关闭ubuntu desktop。

    其中有一点说的是ctrl+alt+f2,桌面可以和命令行转换,在我安装的版本无效,没查到原因。

    要想彻底关闭,可以采用了如下方法:

    sudo vim /etc/default/grub
    找到这一行:GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
    改为:GRUB_CMDLINE_LINUX_DEFAULT="text "或者"quiet splash text"
    保存后sudo update-grub 重启即可。


    3.显卡驱动,cuda安装

    个人使用的是显卡GTX1080,显卡驱动及cuda需要在文本模式下操作,否则会安装失败。

    使用cuda7.5在make runtest时报错

    3.1.对应显卡驱动安装

    http://www.nvidia.cn/Download/index.aspx?lang=cn下载

    3.2.cuda安装

    如果有老的先卸载

    在路径:
    /usr/local/cuda-6.5/bin
    有CUDA自带的卸载工具uninstall_cuda_toolkit_6.5.pl,使用命令:
     sudo ./uninstall_cuda_toolkit_6.5.pl
    然后别忘了卸载cuda samples.也是在/usr/local文件夹下。
    安装很简单,执行cuda_8.0.27_linux-run,驱动不安装,因为已经安装过了。

    in/x86_64/linux/release/deviceQuery,检测是否安装成功

    3.3cudnn安装

    tar xvf cudnn*.tgzcd cuda

    sudo cp */*.h /usr/local/cuda/include/

    sudo cp */libcudnn* /usr/local/cuda/lib64/sudo

     chmod a+r /usr/local/cuda/lib64/libcudnn*

    3.剩下的就按caffe官网安装caffe的方法安装就行了,一路顺畅。

    顺便提醒一下,caffe没有说要安装opencv,这个是需要安装的,可以在所以安装完毕后,安装opencv。

    4.opencv安装,

    4.1ffmpeg:

    sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next
    sudo apt-get update
    sudo apt-get install ffmpeg

    4.2 No rule to make target `/usr/lib/x86_64-linux-gnu/libGL.so', needed by `lib/libopencv_core.so.2.4.11'.  Stop.

    解决方法,删除旧的,然后,重新定向

    ln -s /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/libGL.so.1

    4.3make j导致电脑死机

    改用make,而不适用make j

    4.4以上就是OpenCV安装全过程,安装过程中可能碰到一些问题,例举一些。

    在编译的过程中可能会碰到找不到Qt5文件的情况,只是一个警告可以不理,如果有强迫症的同学可以安装一下Qt5

    <code class="hljs objectivec" style="display: block; padding: 0.5em; color: rgb(0, 0, 0); background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span class="hljs-built_in" style="color: rgb(102, 0, 102);">CMake</span> Warning at cmake/OpenCVFindLibsGUI.cmake:<span class="hljs-number" style="color: rgb(0, 102, 102);">18</span> (find_package):
      By not providing <span class="hljs-string" style="color: rgb(0, 136, 0);">"FindQt5Core.cmake"</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">in</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">CMAKE_MODULE_PATH</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">this</span> project has
      asked <span class="hljs-built_in" style="color: rgb(102, 0, 102);">CMake</span> to find a package configuration file provided by <span class="hljs-string" style="color: rgb(0, 136, 0);">"Qt5Core"</span>, but
      <span class="hljs-built_in" style="color: rgb(102, 0, 102);">CMake</span> did not find one.</code>

    另一个是ICV hash校验值不符的问题

    <code class="hljs groovy" style="display: block; padding: 0.5em; color: rgb(0, 0, 0); background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">CMake Warning at <span class="hljs-number" style="color: rgb(0, 102, 102);">3</span>rdparty<span class="hljs-regexp" style="color: rgb(0, 136, 0);">/ippicv/</span>downloader.<span class="hljs-string" style="color: rgb(0, 136, 0);">cmake:</span><span class="hljs-number" style="color: rgb(0, 102, 102);">54</span> (message):
    <span class="hljs-symbol" style="color: rgb(0, 102, 102);">  ICV:</span> Local copy of ICV <span class="hljs-keyword" style="color: rgb(0, 0, 136);">package</span> has invalid MD5 <span class="hljs-string" style="color: rgb(0, 136, 0);">hash:</span>
      <span class="hljs-number" style="color: rgb(0, 102, 102);">0103</span>b909e19ca9c6497a7ae696c16480 (<span class="hljs-string" style="color: rgb(0, 136, 0);">expected:</span>
      <span class="hljs-number" style="color: rgb(0, 102, 102);">8</span>b449a536a2157bcad08a2b9f266828b)
    Call Stack (most recent call first):
      <span class="hljs-number" style="color: rgb(0, 102, 102);">3</span>rdparty<span class="hljs-regexp" style="color: rgb(0, 136, 0);">/ippicv/</span>downloader.<span class="hljs-string" style="color: rgb(0, 136, 0);">cmake:</span><span class="hljs-number" style="color: rgb(0, 102, 102);">108</span> (_icv_downloader)
      cmake/OpenCVFindIPP.<span class="hljs-string" style="color: rgb(0, 136, 0);">cmake:</span><span class="hljs-number" style="color: rgb(0, 102, 102);">235</span> (include)
      cmake/OpenCVFindLibsPerf.<span class="hljs-string" style="color: rgb(0, 136, 0);">cmake:</span><span class="hljs-number" style="color: rgb(0, 102, 102);">12</span> (include)
      CMakeLists.<span class="hljs-string" style="color: rgb(0, 136, 0);">txt:</span><span class="hljs-number" style="color: rgb(0, 102, 102);">526</span> (include)
    
    
    -- <span class="hljs-string" style="color: rgb(0, 136, 0);">ICV:</span> Downloading ippicv_linux_20141027.tgz...
    CMake Error at <span class="hljs-number" style="color: rgb(0, 102, 102);">3</span>rdparty<span class="hljs-regexp" style="color: rgb(0, 136, 0);">/ippicv/</span>downloader.<span class="hljs-string" style="color: rgb(0, 136, 0);">cmake:</span><span class="hljs-number" style="color: rgb(0, 102, 102);">71</span> (file):
      file DOWNLOAD HASH mismatch
    
        <span class="hljs-keyword" style="color: rgb(0, 0, 136);">for</span> <span class="hljs-string" style="color: rgb(0, 136, 0);">file:</span> [<span class="hljs-regexp" style="color: rgb(0, 136, 0);">/home/</span>jason<span class="hljs-regexp" style="color: rgb(0, 136, 0);">/program/</span>opencv<span class="hljs-number" style="color: rgb(0, 102, 102);">-3.0</span><span class="hljs-number" style="color: rgb(0, 102, 102);">.0</span><span class="hljs-regexp" style="color: rgb(0, 136, 0);">/3rdparty/</span>ippicv<span class="hljs-regexp" style="color: rgb(0, 136, 0);">/downloads/</span>linux<span class="hljs-number" style="color: rgb(0, 102, 102);">-8</span>b449a536a2157bcad08a2b9f266828b/ippicv_linux_20141027.tgz]
          expected <span class="hljs-string" style="color: rgb(0, 136, 0);">hash:</span> [<span class="hljs-number" style="color: rgb(0, 102, 102);">8</span>b449a536a2157bcad08a2b9f266828b]
            actual <span class="hljs-string" style="color: rgb(0, 136, 0);">hash:</span> [<span class="hljs-number" style="color: rgb(0, 102, 102);">0103</span>b909e19ca9c6497a7ae696c16480]
    
    Call Stack (most recent call first):
      <span class="hljs-number" style="color: rgb(0, 102, 102);">3</span>rdparty<span class="hljs-regexp" style="color: rgb(0, 136, 0);">/ippicv/</span>downloader.<span class="hljs-string" style="color: rgb(0, 136, 0);">cmake:</span><span class="hljs-number" style="color: rgb(0, 102, 102);">108</span> (_icv_downloader)
      cmake/OpenCVFindIPP.<span class="hljs-string" style="color: rgb(0, 136, 0);">cmake:</span><span class="hljs-number" style="color: rgb(0, 102, 102);">235</span> (include)
      cmake/OpenCVFindLibsPerf.<span class="hljs-string" style="color: rgb(0, 136, 0);">cmake:</span><span class="hljs-number" style="color: rgb(0, 102, 102);">12</span> (include)
      CMakeLists.<span class="hljs-string" style="color: rgb(0, 136, 0);">txt:</span><span class="hljs-number" style="color: rgb(0, 102, 102);">526</span> (include)</code>

    之后查了很多资料也没有发现也不知道该怎么解决,后来去查了一下代码,发现这个是下载ippicv_linux_20141027.tgz时的校验和不符,查看了配置文件,发现可以自行从http://sourceforge.NET/projects/opencvlibrary/files/3rdparty/ippicv这里下载,奇怪的是编译时从这里下载的文件和自己下载的文件校验值居然不一样,也真是神奇,将下载的文件

    ~/opencv-3.0.0/3rdparty/ippicv/downloads/linux-8b449a536a2157bcad08a2b9f266828b ,代替原来的同名文件,ok问题解决。


    另外对与cuda8.0,opencv3.0或者2.4.10都会报如下错误,使用opencv2.4.13就没有问题。(唯一一个2016年发布的版本)

    Ubuntu/3.0/OpenCV/opencv-3.0.0/modules/cudalegacy/src/graphcuts.cpp:120:54: error: ‘NppiGraphcutState’ has not been declared
         typedef NppStatus (*init_func_t)(NppiSize oSize, NppiGraphcutState** ppState, Npp8u* pDeviceMem);

    5.建议安装Anaconda包,这个包能独立于系统自带的Python库,并且提供大部分Caffe需要的科学运算Python库。这里需要注意,在运行Caffe时,可能会报一些找不到libxxx.so的错误,而用 locate libxxx.so命令发现已经安装在anaconda中,这时首先想到的是在/etc/ld.so.conf.d/ 下面将 $your_anaconda_path/lib 加入 LD_LIBRARY_PATH中。 但是这样做可能导致登出后无法再进入桌面!!!原因(猜测)可能是anaconda的lib中有些内容于系统自带的lib产生冲突。


    正确的做法是:为了不让系统在启动时就将anaconda/lib加入系统库目录,可以在用户自己的~/.bashrc 中添加library path, 比如我就在最后添加了两行

    # add library path
    LD_LIBRARY_PATH=your_anaconda_path/lib:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH

    安装anaconda后再安装opencv会有警告

    anaconda2/lib/libcurl.so.4: no version information available

    此事需要先屏蔽掉以上环境变量,等编译通过以后再放开。

    6.caffe编译

    首先按个人需求修改Makefile.config配置文件

    make runtest报错

     error while loading shared libraries: libcudart.so.8.0

    在bashrc中添加如下环境变量即可:

    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64/


    make时出现的问题:

    (1).build_release/lib/libcaffe.so: undefined reference to google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'

    设置环境变量:LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/:$LD_LIBRARY_PATH,将/usr/lib/x86_64-linux-gnu/放在最前面

    (2)/cudnn.hpp:8:34: fatal error: caffe/proto/caffe.pb.h: No such file or directory

    make all -j8有问题,make all没问题。可能是多核编译的问题。


    win7上安装,就直接按github上的说明安装,vs一定要用2013.这个我学乖了,所有版本按说明来,安装很顺畅。

    win注意点:1.GPU模式下,cuda对显卡的加速能力有要求,cudnn需要加速能力3.0以上,具体要求没找到。我的显卡不太高端,所以我把cudnn禁用了。

    2.cuda的在comm中的默认配置加速能力是最低3_5,如果显卡性能达不到,需要修改,我的是3.4M的显卡,所以我改成了3_0。

  • 相关阅读:
    万能的everything彻底解决mysql问题
    乱码问题
    机器学习学习规划
    NG机器学习笔记
    书籍与博客
    技术规划
    反置数
    多个接口出现同名函数的处理-转
    接口-imploements-委托
    接口使用中,对象生命周期管理-转
  • 原文地址:https://www.cnblogs.com/huty/p/8517695.html
Copyright © 2011-2022 走看看