Ubuntu 安装 Caffe

Caffe

Caffe 安装(Python2 CPU版本)

  • 参考博文https://blog.csdn.net/pangyunsheng/article/details/79418896

  • 安装环境

    • Ubuntu 16.04 STL
    • Python 2.7(Caffe对Python3支持不好)
  • 安装步骤

    1. apt安装依赖

      • sudo apt-get install python-pip
      • pip install ipython==5.3.0 --user
      • pip install matplotlib==2.2.3 --user
      • pip install 'scikit-image<0.15' --user
      • sudo apt-get install python-numpy
      • sudo apt-get install libprotobuf-dev
      • sudo apt-get install libleveldb-dev
      • sudo apt-get install libsnappy-dev
      • sudo apt-get install libopencv-dev
      • sudo apt-get install libhdf5-serial-dev
      • sudo apt-get install protobuf-compiler
      • sudo apt-get install libgflags-dev
      • sudo apt-get install libgoogle-glog-dev
      • sudo apt-get install liblmdb-dev
      • sudo apt-get install libatlas-base-dev
      • sudo apt-get install --no-install-recommends libboost-all-dev
      • sudo apt-get install git
    2. 克隆caffe项目

      • mkdir ~/Documents/GitRepos
      • cd ~/Documents/GitRepos: 在当前用户的Documents目录下创建GitRepos目录用于存放git克隆下来的项目
      • git clone git://github.com/BVLC/caffe.git
    3. 配置caffe的Makefile

      • cd caffe
      • cp Makefile.config.example Makefile.config
      • 修改Makefile.config配置文件
        • 去掉CPU_ONLY前面的注释
        • INCLUDE_DIRS中添加/usr/include/hdf5/serial
        • LIBRARY_DIRS中添加/usr/lib/x86_64-linux-gnu/hdf5/serial
    4. 通过make编辑

      • make all -j 4
      • make test -j 4
      • make runtest
    5. 编译Python 2接口

      • cd python
      • for req in $(cat requirements.txt); do pip install $req; done
      • pip install -r requirements.txt --user
      • export PYTHONPATH=~/Documents/GitRepos/caffe/python:$PYTHONPATH
      • exec "$SHELL"
      • cd ..
      • make pycaffe -j 4
      • 重启一个Terminal
      • python
      • import caffe: 没有提示模块没有扎到则正确

Caffe(Python3虚拟环境 CPU版本)

  1. apt安装依赖(请先安装pyenv, 并切换到Python3的虚拟环境)

     + `sudo apt-get install python3-pip`
     + `sudo apt-get install python-numpy`
     + `sudo apt-get install libprotobuf-dev`
     + `sudo apt-get install libleveldb-dev`
     + `sudo apt-get install libsnappy-dev`
     + `sudo apt-get install libopencv-dev`
     + `sudo apt-get install libhdf5-serial-dev`
     + `sudo apt-get install protobuf-compiler`
     + `sudo apt-get install libgflags-dev`
     + `sudo apt-get install libgoogle-glog-dev`
     + `sudo apt-get install liblmdb-dev`
     + `sudo apt-get install libatlas-base-dev`
     + `sudo apt-get install --no-install-recommends libboost-all-dev`
     + `sudo apt-get install git`
    
    1. 克隆caffe项目

      • mkdir ~/Documents/GitRepos
      • cd ~/Documents/GitRepos: 在当前用户的Documents目录下创建GitRepos目录用于存放git克隆下来的项目
      • git clone git://github.com/BVLC/caffe.git
    2. 配置caffe的Makefile

      • cd caffe
      • cp Makefile.config.example Makefile.config
      • 修改Makefile.config配置文件
        • 去掉CPU_ONLY前面的注释
        • INCLUDE_DIRS中添加/usr/include/hdf5/serial
        • LIBRARY_DIRS中添加/usr/lib/x86_64-linux-gnu/hdf5/serial
        • 注释掉PYTHON2的项
        • PYTHON_INCLUDE := /home/yourname/.pyenv/versions/3.5.2/include/python3.5m \ /home/yourname/.pyenv/versions/3.5.2/lib/python3.5/site-packages/numpy/core/include
        • 取消PYTHON_LIBRARIES的注释, 修改为PYTHON_LIBRARIES := boost_python-py35 python3.5m
        • 注意: 到/usr/lib/x86_64-linux-gnu目录下确定存在libboost_python3.5m.so, 如果没有则将虚拟环境中的复制过来
        • 修改PYTHON_LIB := /home/yourname/.pyenv/versions/3.5.2/lib
        • 取消WITH_PYTHON_LAYER := 1的注释
    3. 通过make编辑

      • make all -j 4
      • make test -j 4
      • make runtest
    4. 编译Python 3接口

      • cd python
      • pip install -r requirements.txt --user
      • export PYTHONPATH=~/Documents/GitRepos/caffe/python:$PYTHONPATH
      • exec "$SHELL"
      • cd ..
      • make pycaffe -j 4
      • 重启一个Terminal
      • python
      • import caffe: 没有提示模块没有扎到则正确
posted @ 2019-04-04 18:03  gogogo11  阅读(645)  评论(0编辑  收藏  举报