ubuntu安装caffe遇到的一些问题(重新整理)

以前没有用maekdown编译,感觉好丑,重新整理一下博客

Caffe 安装

1、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 python-skimage ipython python-pil python-h5py ipython python-gflags python-yaml  
    sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev  

2、克隆caffe

    cd ~/git  
    git clone https://github.com/BVLC/caffe.git  
    cd caffe  
    cp Makefile.config.example Makefile.config  

3、如果安装了cuDNN然后把Makefile文件的USE_CUDNN := 1注释去掉

  sed -i 's/# USE_CUDNN := 1/USE_CUDNN := 1/' Makefile.config  

4、如果安装了OpenBLAS,修改BLAS参数

sed -i 's/BLAS := atlas/BLAS := open/' Makefile.config  

5、安装需求build和测试caffe,编译PyCaffe

    sudo pip install -r python/requirements.txt  
    make all -j $(($(nproc) + 1))  
    make test -j $(($(nproc) + 1))  
    make runtest -j $(($(nproc) + 1))  
    make pycaffe -j $(($(nproc) + 1))  

6、添加caffe的环境变量

    echo 'export CAFFE_ROOT=$(pwd)' >> ~/.bashrc  
    echo 'export PYTHONPATH=$CAFFE_ROOT/python:$PYTHONPATH' >> ~/.bashrc  
    source ~/.bashrc  

7、测试caffe接口

    ipython  
    >>> import caffe  
    >>> exit() 

理论上以上都能成功安装,但是还是可能会报错的,这篇博客对报错描写的很详细

http://blog.csdn.net/u012576214/article/details/68947893

解决办法是依据出现错误的顺序而给出的,为了方便,可以直接先执行所有解决办法后再安装caffe。

1. ./include/caffe/common.hpp:5:27: fatal error: gflags/gflags.h: No such file or directory

解决办法:sudo apt-get install libgflags-dev

2./include/caffe/util/mkl_alternate.hpp:14:19: fatal error: cblas.h: No such file or directory

解决办法:sudo apt-get install libblas-dev

3. ./include/caffe/util/hdf5.hpp:6:18: fatal error: hdf5.h: No such file or directory

解决办法:在Makefile.config找到以下行并添加蓝色部分

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/hdf5/serial

3.1 如果仍然提示找不到lhdf5和lhdf5_h

(这是因为ubuntu16.04的文件包含位置发生了变化,尤其是需要用到的hdf5的位置,所以需要更改这一路径)选自 caffe —找不到lhdf5_hl和lhdf5的错误

解决办法:然后根据情况执行下面两句:

cd /usr/lib/x86_64-linux-gnu

sudo ln -s libhdf5_serial.so.10.1.0 libhdf5.so

sudo ln -s libhdf5_serial_hl.so.10.0.2 libhdf5_hl.so

4. ./include/caffe/util/db_lmdb.hpp:8:18: fatal error: lmdb.h: No such file or directory

解决办法:sudo apt install liblmdb-dev

5. /usr/bin/ld: cannot find -lcblas /usr/bin/ld: cannot find -latlas

解决办法:sudo apt install libatlas-base-dev

6. 遇到CMake Error at cuda_compile_generated_detection_output_layer.cu.o.cmake:266

解决办法:由于gcc版本问题导致的

升级GCC版本

    sudo add-apt-repository ppa:ubuntu-toolchain-r/test  
    sudo apt-get update  
      
    #如果提示未安装,还需要先安装它的包:  
    sudo apt-get install software-properties-common  
      
    sudo apt-get install gcc-5 g++-5  
      
    cd /usr/bin  
      
    sudo rm gcc  
      
    sudo ln -s gcc-5 gcc  
    sudo rm g++   
    sudo ln -s g++-5 g++  

7. 遇到 "libcudart.so.8.0 cannot open shared object file: No such file or directory

解决办法是将一些文件复制到/usr/local/lib文件夹下:

#注意自己CUDA的版本号!

sudo cp /usr/local/cuda-8.0/lib64/libcudart.so.8.0 /usr/local/lib/libcudart.so.8.0 && sudo ldconfig

8. 遇到Failed to compile cuda_ndarray.cu: libcublas.so.7.5: cannot open shared object file(CUDA7.5)

sudo ldconfig /usr/local/cuda-7.5/lib64

9. Linux(Ubuntu) :ImportError: No module named google.protobuf.internal

sudo apt-get install python-protobuf

10. libopencv-dev依赖出了问题,无法安装

在执行sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler这一行特么的,就libopencv-dev这个包出了问题

出现下面问题,真他么是日了,网上的一大堆教程都试过,最终还是选择的换源,但是换什么源比较适合,又试了一大堆,

libopencv-dev : 依赖: libopencv-objdetect-dev (= 2.4.8+dfsg1-2ubuntu1) 。。。

下面参考http://blog.csdn.net/wopawn/article/details/52302164

开始添加源

终端输入

cd /etc/apt/
sudo cp sources.list sources.list.bak

然后

sudo gedit /etc/apt/sources.list

将下面源添加到最后一行

deb http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

然后更新源和更新已安装的包:
终端输入
sudo apt-get update
sudo apt-get upgrade

再安装这些依赖应该就没问题了

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler

http://blog.csdn.net/zziahgf/article/details/72900948

版权声明:本文为CSDN博主「hjxu2016」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/hjxu2016/article/details/70256147

你可能感兴趣的:(ubuntu,系统,caffe)