在Ubuntu系统中安装caffe2 2018-11-12
在Ubuntu系统中安装caffe2
安装顺序:
安装cuda--------安装cudnn---------源码编译安装Caffe2
安装cuda的教程我的上一篇文章已经详细说明了,接下来就写剩下的两个步骤。
1.安装cudnn
1.1 去官网下载cudnn安装包
1.2解压缩cuDNN包。
sudo tar -xzvf cudnn-9.0-linux-x64-v7.tgz
![](https://img.haomeiwen.com/i14907724/21400db9a602aedd.png)
1.3将以下文件复制到CUDA Toolkit目录中,然后更改文件权限。
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
2.安装caffe2
2.1安装依赖项
sudo apt-get update
![](https://img.haomeiwen.com/i14907724/fdabbd7f9deecf74.png)
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
![](https://img.haomeiwen.com/i14907724/63b7904a7d38ad30.png)
pip install--user\
future\
numpy\
protobuf\
typing\
hypothesis
![](https://img.haomeiwen.com/i14907724/4edbaf1c553dbcc7.png)
如果出现以下错误:
![](https://img.haomeiwen.com/i14907724/b68af863834a2338.png)
它的解决方法是:
![](https://img.haomeiwen.com/i14907724/f5dba955dd0f2f07.png)
![](https://img.haomeiwen.com/i14907724/a1a7e2879c9409d0.png)
2.2 for Ubuntu 16.04
sudo apt-get install-y--no-install-recommends\
libgflags-dev\
cmake
![](https://img.haomeiwen.com/i14907724/e207ebedb3ba1abb.png)
2.3克隆与构建
git clone https://github.com/pytorch/pytorch.git && cd pytorch
git submodule update--init-- recursive
sudo python setup.py install
![](https://img.haomeiwen.com/i14907724/d409e5a811a8d870.png)
![](https://img.haomeiwen.com/i14907724/37f5072843ca45e8.png)
![](https://img.haomeiwen.com/i14907724/2a7c7e15694db554.png)
3.测试Caffe2安装
cd ~ && python -c 'from caffe2.python importcore' 2>/dev/null && echo "Success" || echo "Failure"
![](https://img.haomeiwen.com/i14907724/ac9d4499598cd2ed.png)
安装成功!