caffe安装和配置基于Ubuntu16.04

来源:互联网 发布:手持gps数据采集器 编辑:程序博客网 时间:2024/06/07 03:18

caffe安装和配置基于Ubuntu16.04

本文是在ubuntu16.04安装caffe,由于显卡比较烂,所以采用了CPU-only的安装模式
参考 自caffe

  • 1.安装依赖

  • 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

  • 2.由于是CPU-only,跳过CUDA安装,安装BLAS,CUDA安装见官网
sudo apt-get install libatlas-base-dev
  • 3.建立pycaffe接口
sudo apt-get install python-dev
  • 4.下载caffe
  • 我没有下载git,所以首先下载git:
sudo apt-get install git
  • 下载caffe:
git clone https://github.com/BVLC/caffe.git
  • 5.切换到caffe下的python目录,安装pip和python依赖库
sudo apt-get install python-pip  for req in $(cat requirements.txt); do pip install $req; done 
  • 6.编译Caffe
    切换到caffe目录下,将Makefile.config.example复制并重命名成Makefile.config
cp Makefile.config.example Makefile.config# Adjust Makefile.config (for example, if using Anaconda Python, or if cuDNN is desired)

打开Makefile.config,并找到如下两个地方并修改为下面:

gedit Makefile.config
# Whatever else you find you need goes here.  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 
# NOTE: this is required only if you will compile the python interface.  # We need to be able to find Python.h and numpy/arrayobject.h.  PYTHON_INCLUDE := /usr/include/python2.7 \          /usr/lib/python2.7/dist-packages/numpy/core/include 

之后编译,后面加 -j8会加快编译速度:
make pycaffe
make all
make test
make runtest

  • 7.测试
    切换到caffe/python文件目录下,记录下来当前路径(pwd命令)
    并且添加到环境变量:
gedit ~/.bashrc

最后面添加:

export PYTHONPATH=(pwd出来的路径):$PYTHONPATH  
source ~/.bashrc

生效。
切换到python工作环境:

import caffe

不报错,则成功


原创粉丝点击