zoukankan      html  css  js  c++  java
  • Caffe环境安装

    一、安装依赖包:

      sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-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

      sudo apt-get install git cmake build-essential

    二、安装protobuf

           1.删除系统原生protobuf

        sudo rm -rf protoc

           2.确认当前protobuf是否已删除

      3.安装protobuf2.6.1

                cd protobuf2.6.1

       ./configure

       make

       sudo make install

               sudo ldconfig

      4.确认当前protobuf版本

    三、安装opencv3.4.6

      mkdir build && cd build # 创建编译的文件目录,并进入该目录

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

      注:在docker环境下安装时,碰到一个问题:/usr/bin/ld: warning: libzstd.so.1.3.7, needed by //opt/conda/lib/libtiff.so.5, not found (try using -rpath or -rpath-link)

      解决方法:加上选项:-D BUILD_TIFF=ON

       cmake -D BUILD_TIFF=ON -D CMAKE_BUILD_TYPE=Release -D ENABLE_PRECOMPILED_HEADERS=OFF -D CMAKE_INSTALL_PREFIX=/usr/local ..

      make -j8  #编译

      sudo make install #安装

      pkg-config --modversion opencv  #验证成功与否

    四、安装依赖包

      1)sudo apt-get install libhdf5-dev

    五、安装caffe

      sudo cp Makefile.config.example Makefile.config

    1、修改Makefile.config
           sudo gedit Makefile.config
           应用 opencv 版本将
           #OPENCV_VERSION := 3   修改为: OPENCV_VERSION := 3
           修改 python 路径
           INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
           LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
           修改为:
           INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
           LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial     

    2、修改Makefie

           修改 caffe 目录下的 Makefile 文件
           将:NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
           替换为:NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
           将:LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
           改为:LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

    3、编译caffe

           make all -j8

           问题1: 在运行上面命令编译时,报错://opt/conda/lib/libpng16.so.16: undefined reference to `inflateValidate@ZLIB_1.2.9

           原因:zlib的版本不兼容导致,这里指出是ZLIB1.2.9,本地安装的是zlib1.2.8

           解决方法:

    wget http://www.zlib.net/fossils/zlib-1.2.9.tar.gz
    tar -xvf zlib-1.2.9.tar.gz
    cd zlib-1.2.9
    mkdir build
    cd build
    cmake ..
    make
    make install

          sudo make runtest -j8  #测试caffe安装是否成功

          sudo apt-get install python3.8-dev

          sudo make pycaffe-j8   #生成最终版本

    4.运行caffe

    问题1:  import caffe时报错:

      Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/li.guangyao/Programming/caffe/python/caffe/__init__.py", line 1, in <module> from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer File "/home/li.guangyao/Programming/caffe/python/caffe/pycaffe.py", line 13, in <module> from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, ImportError: /home/li.guangyao/Programming/caffe/python/caffe/_caffe.so:

     undefined symbol: _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE

    解决方法:

     先使用以下命令,安装最新版本libboost: sudo apt-get install --no-install-recommends libboost-all-dev

        打开caffe目录下Makefile文件:

    将PYTHON_LIBRARIES := boost_python python2.7
    PYTHON_LIBRARIES := boost_python-py36 #py36需要改为你自己的python版本,如py34,py33

     问题2:修改完问题1,指定PYTHON_LIBRARIES版本为3.6,编译make pycaffe时又报错:/usr/bin/ld: cannot find -lboost_python-py36

     解决方法:

      1.下载包boost_1_67_0,进入boost源文件目录boost_1_67_0

      2.运行以下两条命令:

    ./bootstrap.sh --with-libraries=python --with-toolset=gcc
    ./b2 cflags='-fPIC' cxxflags='-fPIC' --with-python include="/qp/3rd/anaconda3/include/python3.6m/"
     3.sudo ./b2 install

    编译安装成功后,/usr/local/lib下会有libboost_python36.so和libboost_python36.a,有些应用link时需要的是libboost_python3.so或者libboost_python3.a,我们建个软链:

    cd /usr/local/lib
    sudo ln -s libboost_python-py36.so libboost_python3.so
    sudo ln -s libboost_python-py36.a libboost_python3.a

    问题3:ModuleNotFoundError: No module named 'skimage'
    解决方法:pip install scikit-image

    问题4:ModuleNotFoundError: No module named 'google'
    解决方法:pip install google
    pip install protobuf

      

        

  • 相关阅读:
    [置顶] windows player,wzplayerV2 for windows
    wzplayer 近期将会支持BlackBerry和WinPhone8
    wzplayerEx for android(真正硬解接口,支持加密的 player)
    ffmpeg for ios 交叉编译 (支持i686 armv7 armv7s) 包含lame支持
    ffmpeg for ios 交叉编译 (支持i686 armv7 armv7s) 包含lame支持
    编译cegcc 0.59.1
    wzplayer 近期将会支持BlackBerry和WinPhone8
    wzplayerEx for android(真正硬解接口,支持加密的 player)
    windows player,wzplayerV2 for windows(20140416)更新
    编译cegcc 0.59.1
  • 原文地址:https://www.cnblogs.com/jimchen1218/p/14257967.html
Copyright © 2011-2022 走看看