caffe2安装
安装前说明:到目前日期为止,大多数博客中介绍的方法是从 {git clone --recursive https://github.com/caffe2/caffe2.git} 中进行git代码,然而我们可以从git网站中看到这个caffe2.git已被移动到pytorch/pytorch repo。
因此,我们参考官方给出的安装说明来安装caffe2:https://caffe2.ai/docs/getting-started.html?platform=windows&configuration=compile
1)更新和安装依赖项
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
build-essential \
git \
libgoogle-glog-dev \
libgtest-dev \
libiomp-dev \
libleveldb-dev \
liblmdb-dev \
libopencv-dev \
libopenmpi-dev \
libsnappy-dev \
libprotobuf-dev \
openmpi-bin \
openmpi-doc \
protobuf-compiler \
python-dev \
python-pip
这里注意,若 执行命令 sudo apt-get install libopencv-dev 报错,则采用以下命令解决:
sudo apt-get install build-essential make cmake git libgtk2.0-dev pkg-config python python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev libjpeg-dev libpng-dev libtiff-dev
2)pip安装常用lib
sudo python2 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --user \
future \
numpy \
protobuf \
typing \
hypothesis
以上需要注意的是,将这些libs安装到了python2还是python3?我们这里是安装到了python2
# for Ubuntu 14.04
sudo apt-get install -y --no-install-recommends \
libgflags2 \
cmake3
# for Ubuntu 16.04
sudo apt-get install -y --no-install-recommends \
libgflags-dev \
cmake
以上需要注意的是,根据ubuntu版本选择安装命令。
3)安装显卡驱动、CUDA、cuDNN(在pytorch的caffe2版本需要cuda9.0+cudnn7.0以上)
输入以下命令,分别查看cuda和cudnn版本
nvcc -V
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
这里的nvidia-smi驱动的安装、CUDA、cuDNN的安装,最好不要安装caffe2的官方给出的方式安装,请参考https://blog.csdn.net/zbzb1000/article/details/52864131 ,安装CUDA9.0和cuDNN7.0
4)安装caffe2:
下载并且进入到pytorch目录:
git clone https://github.com/pytorch/pytorch.git && cd pytorch
git submodule update --init --recursive
python setup.py install
这里若在执行 {python setup.py install} 出现 Error:caffe2 requires CUDA9.0,则表示cuda版本不符合要求,需要返回第三步重新安装cuda9.0
5)测试:
cd ~ && python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"
交互得到success,则表示caffe2安装成功。