当先锋百科网

首页 1 2 3 4 5 6 7

Caffe2 - From Source 安装

1. 安装

平台
- Ubuntu14.04
- Ubuntu16.04

从Source安装

依赖项:

sudo apt-get update
sudo apt-get install -y --no-install-recommends \
      build-essential \
      cmake \
      git \
      libgoogle-glog-dev \
      libprotobuf-dev \
      protobuf-compiler \
      python-dev \
      python-pip                          
sudo pip install numpy protobuf

GPU 支持

需要安装 NVIDIA CUDA 8cuDNN v5.1v6.0,官方推荐安装方式如下:

Step1 安装显卡驱动:
  • Ubuntu14.04
sudo apt-get update && sudo apt-get install wget -y --no-install-recommends
wget "http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_8.0.61-1_amd64.deb"
sudo dpkg -i cuda-repo-ubuntu1404_8-_amd64.deb
sudo apt-get update
sudo apt-get install cuda
  • Ubuntu16.04
sudo apt-get update && sudo apt-get install wget -y --no-install-recommends
wget "http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb"
sudo dpkg -i cuda-repo-ubuntu1604_8-_amd64.deb
sudo apt-get update
sudo apt-get install cuda
Step2 安装cuDNN
  • cuDNN v5.1
CUDNN_URL="http://developer.download.nvidia.com/compute/redist/cudnn/v5.1/cudnn-8.0-linux-x64-v5.1.tgz"
wget ${CUDNN_URL}
sudo tar -xzf cudnn--linux-x64-v5.tgz -C /usr/local
rm cudnn--linux-x64-v5.tgz && sudo ldconfig

其它依赖项

  • Ubuntu14.04 – libgflags2
# for Ubuntu 14.04
sudo apt-get install -y --no-install-recommends libgflags2
  • Ubuntu16.04 – libgflags-dev
# for Ubuntu 16.04
sudo apt-get install -y --no-install-recommends libgflags-dev
  • 其它依赖项
# for both Ubuntu 14.04 and 16.04
sudo apt-get install -y --no-install-recommends \
      libgtest-dev \
      libiomp-dev \
      libleveldb-dev \
      liblmdb-dev \
      libopencv-dev \
      libopenmpi-dev \
      libsnappy-dev \
      openmpi-bin \
      openmpi-doc \
      python-pydot
sudo pip install \
      flask \
      graphviz \
      hypothesis \
      jupyter \
      matplotlib \
      pydot python-nvd3 \
      pyyaml \
      requests \
      scikit-image \
      scipy \
      setuptools \
      tornado

编译

git clone --recursive https://github.com/caffe2/caffe2.git
cd caffe2
make
cd build
sudo make install
python -c 'from caffe2.python import core' >/dev/null && echo "Success" || echo "Failure"

运行命令测试GPU-Caffe2是否编译成功:

python -m caffe2.python.operator_test.relu_op_test

环境变量设置

sudo vim ~/.bashrc
# 添加对应内容
source
echo $PYTHONPATH
# export PYTHONPATH=/usr/local:$PYTHONPATH
# export PYTHONPATH=$PYTHONPATH:/home/ubuntu/caffe2/build
echo $LD_LIBRARY_PATH
# export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

2. 错误解决

1 - ImportError: No module named past.builtins

错误问题:
安装完成后,运行:
python -c ‘from caffe2.python import core’ 2>/dev/null && echo “Success” || echo “Failure”
出现 Failure;
运行:
python -m caffe2.python.operator_test.relu_op_test
出现以下错误:

Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line , in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line , in _run_code
    exec code in run_globals
  File "/usr/local/caffe2/python/operator_test/relu_op_test.py", line , in <module>
    from caffe2.python import core
  File "/usr/local/caffe2/python/core.py", line , in <module>
    from past.builtins import basestring
ImportError: No module named past.builtins

解决方案:
安装 future package:

sudo  pip install future

2. gmock/gmock.h

ubuntu下 google gmock 安装.
下载 googletest,并解压

./travis.sh
cmake ./CMakeLists.txt
make
sudo make install