http://http://blog.csdn.net/meccaendless/article/de由于之前已经配置好了ubuntu16.04+cuda9.1+cudnn7.04环境,参考我的这篇博文。这里不再赘述,caffe2官方安装说明讲的很详细,是按照ubuntu14.04和16.04分开说明的,这里只讲一下16.04下安装,基本上完全参考了官方安装步骤:
1.首先安装依赖项:
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
sudo apt-get install -y --no-install-recommends libgflags-dev
其它依赖项
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
2.编译:
git clone --recursive https://github.com/caffe2/caffe2.git
cd caffe2
sudo make
cd build
sudo make install
python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"
这里显示success说明安装成功,若是Failure,在终端输入
python -c 'from caffe2.python import core'
看提示的ImportError:,缺什么库就sudo pip install下
如提示:
Traceback (most recent call last):
File "", line 1, in
File "caffe2/python/core.py", line 24, in
from past.builtins import basestring
ImportError: No module named past.builtins
对应的解决方案是安装sudo pip install future 或者 pip install future --user
运行命令测试GPU-Caffe2是否编译成功:
python -m caffe2.python.operator_test.relu_op_test
若出现
Ran 1 test in 0.661s
OK
说明安装成功,若运行时间在数秒,可能是显卡性能问题,也可能cuda没有工作
3.环境变量设置
sudo gedit ~/.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
错误提示:
在sudo pip install 安装支持包的时候终端可能会提示以下黄色的warning:
The directory ' xxxxxx' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
若出现以上提示,在sudo后加 -H,即sudo -H pip install。
每一步安装不能有报错,否则后面部署深度学习平台时会报错