caffe2 installation Build From Source in Ubuntu 16.04

初衷

本人在安裝caffe2時,遇坑無數。寫此文檔避免後人入坑。

技術總結

環境

Ubuntu 16.04
已安裝cuda9.0 和 cudnn7.0

安裝依賴

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                          
pip install --user \
      future \
      numpy \
      protobuf \
      typing \
      hypothesis

# 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

Clone & Build

設置postBuffer,否則容易出現clone中斷,在編譯過程中也還出現各種各樣的問題。

# set postBuffer
git config --global http.postBuffer 1048576000
# set proxy, if you surfing on the internet through ss
git config --global http.proxy 'socks5://127.0.0.1:1080' 
git config --global https.proxy 'socks5://127.0.0.1:1080'

git clone --recursive https://github.com/pytorch/pytorch
cd pytorch
git checkout v1.0.0
git submodule update --recursive
python setup.py install

測試

# 檢驗caffe2是否成功:運行結果爲Success,則安裝成功

cd ~ && python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"

# 檢驗GPU-caffe2是否成功:

python caffe2/python/operator_test/activation_ops_test.py
# 或者 
from caffe2.python import core
# 運行是否報錯

參考資料:
[1]: https://caffe2.ai/docs/getting-started.html?platform=ubuntu&configuration=compile
[2]: https://blog.fazero.me/2015/07/11/用shadowsocks加速git-clone/
[3]: https://github.com/pytorch/pytorch/issues/13962

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章