caffe2 ubuntu16.04 安装方法
Caffe2的安装相比于caffe在安装的时候更加简便,略去了Makefile.config的各种配置,对于有无GPU以及各种可选库例如opencv,anaconda的支持也更简单。(其实你直接装好库以后make就好,以GPU为例,在make的时候,自动检测你是否安装了CUDA,若没有,就自动CPU only)
在开始安装之前,附上caffe2的官方链接,官网对于安装还是讲的非常详细易懂:https://caffe2.ai/docs/getting-started.html?platform=ubuntu&configuration=compile
依赖库的安装&&驱动
sudo apt-get remove - -purge nvidia-* sudo apt-get remove - -purge cuda-* sudo apt-get install -y nvidia-390 sudo apt-get install -y --no-install-recommends \ build-essential \ cmake \ 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 pip install --user \ future \ numpy \ protobuf sudo apt-get install -y --no-install-recommends libgflags-dev reboot
Optional GPU Support
重启之后看显卡信息是否正常
nvidia-smi,会出来如下显卡信息。
比如我的是
编辑
自动检测是否安装了CUDA,若没有,就自动CPU only
For Ubuntu 16.04
wget "https://developer.download.nvidia.com/compute/machine-learning/nccl/secure/v2.3/prod/nccl-repo-ubuntu1604-2.3.4-ga-cuda9.0_1-1_amd64.deb?J3znnX-iZotY0RJhyKp3_TZlTJ7Ta9Z4bm2Y0MaXw-bdBHV7ZEWYHjZGDYo92KuXs_o7fKuNEu2mY8posIsVbi6VfRfDr_B7SYNExEa6ClChKR3Mki0VHULZEwFEhs4Pkad61iHxAun43xBO9eX-3BnIjkA0Ce4GSkoENK-K7yIJse6TOLPB97VgyBQ17w9VZUulqc3u-ZFWBn87zkNBskU" sudo dpkg -i nccl-repo-ubuntu1604-2.3.4-ga-cuda9.0_1-1_amd64.deb sudo apt-get update wget "https://developer.download.nvidia.com/compute/cuda/9.0/secure/Prod/local_installers/cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb?itJIvC4Gf3WfjcM6JoqP4rn10qgHOH2tESeXlzt-uATJCQ4jKhTlcEbKQoEP2grXzRfQVvH4AsbUUXmzgk-onHAei_idvhi0eGvlQIqdM5AKbMz__RMIqtEEnlBdIelK7A6qgHeC7Iu6IUqE-s0It_hiohu2gMU3cnFvZJIWQhvKhdFEQ0yMe5ANppWeBYwcz5HcEaMXr8xOV_MlhHD7" sudo dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb sudo apt-key add /var/cuda-repo-9-0-local7fa2af80.pub sudo apt-get update sudo apt-get install cuda
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 -H pip install --upgrade pip ##这里更新一下pip,否则后面pip安装jupyter有可能会报错 sudo pip install \ flask \ future \ graphviz \ hypothesis \ jupyter \ matplotlib \ pydot python-nvd3 \ pyyaml \ requests \ scikit-image \ scipy \ setuptools \ six \ 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' 2>/dev/null && echo "Success" || echo "Failure"
环境变量设置
vim $PYTHONPATH # export PYTHONPATH=/usr/local:$PYTHONPATH # export PYTHONPATH=$PYTHONPATH:/home/pengyu/caffe2/build echo $LD_LIBRARY_PATH # export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
参考文献
caffe2 官方安装教程:https://caffe2.ai/docs/getting-started.html?platform=ubuntu&configuration=compile