ubuntu14.04_caffe2安裝

今天F8開發者大會上,Facebook正式發佈Caffe2.通過一天的折騰,終於在ubuntu14.04上成功配置caffe2,現將經驗分享以下:python

1.ubuntu14.04系統下caffe2所需依賴包安裝,不少依賴包在安裝caffe時已經安裝,這個咱們不須要管,安裝過得依賴包會自動跳過:linux

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

2.GPU(可選擇)git

   若是時caffe老用戶,那麼這一步自行跳過,安裝命令以下:github

   2.1 CUDA安裝redis

sudo apt-get update && sudo apt-get install wget -y --no-install-recommends
wget "http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_8.0.61-1_amd64.deb"
sudo dpkg -i cuda-repo-ubuntu1404_8.0.61-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda

    2.2  CUDNN安裝flask

CUDNN_URL="http://developer.download.nvidia.com/compute/redist/cudnn/v5.1/cudnn-8.0-linux-x64-v5.1.tgz"
wget ${CUDNN_URL}
sudo tar -xzf cudnn-8.0-linux-x64-v5.1.tgz -C /usr/local
rm cudnn-8.0-linux-x64-v5.1.tgz && sudo ldconfig

3.可選擇的依賴包(這個能夠在後期須要時再安裝)ubuntu

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
# for Ubuntu 14.04
sudo apt-get install -y --no-install-recommends libgflags2

4.clone&buildapp

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"

  以後,運行如下代碼,驗證GPU是否安裝成功python2.7

python -m caffe2.python.operator_test.relu_op_test

在我運行以後出現以下報錯:tornado

Traceback (most recent call last):
  File "/home/hzz/anaconda2/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/home/hzz/anaconda2/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/hzz/caffe2/build/caffe2/python/operator_test/relu_op_test.py", line 7, in <module>
    from hypothesis import given
ImportError: No module named hypothesis

針對提示錯誤,缺乏hypothesis庫,運行如下命令

pip install hypothesis

而後再次輸入以前測試命令,運行成功,結果以下:

Trying example: test_relu(self=<__main__.TestRelu testMethod=test_relu>, X=array([[-0.86028236,  1.        ,  0.61849821, -0.7184248 ,  0.89307433],
       [ 0.92490983,  1.        ,  0.90946507, -0.37061477, -0.67617983],
       [ 0.07383067,  0.55851477,  0.90312296, -0.94337231,  0.95312852],
       [-0.50963259,  0.83218467,  0.86731863,  0.63752574,  0.0466823 ],
       [ 0.87043667, -1.        ,  0.66159999,  0.10338549,  0.        ]], dtype=float32), gc=, dc=[, device_type: 1], engine=u'')
Trying example: test_relu(self=<__main__.TestRelu testMethod=test_relu>, X=array([ -2.72050470e-01,  -1.68155816e-44,   1.22070059e-01], dtype=float32), gc=, dc=[, device_type: 1], engine=u'')
Trying example: test_relu(self=<__main__.TestRelu testMethod=test_relu>, X=array([[-0.27205047],
       [-0.        ],
       [ 0.81497574],
       [ 0.        ]], dtype=float32), gc=, dc=[, device_type: 1], engine=u'')
Trying example: test_relu(self=<__main__.TestRelu testMethod=test_relu>, X=array([ 0.], dtype=float32), gc=device_type: 1, dc=[, device_type: 1], engine=u'CUDNN')
Trying example: test_relu(self=<__main__.TestRelu testMethod=test_relu>, X=array([ 0.80068815,  0.1997007 ,  1.        , -0.46049505], dtype=float32), gc=, dc=[, device_type: 1], engine=u'CUDNN')
Trying example: test_relu(self=<__main__.TestRelu testMethod=test_relu>, X=array([ 0.73503637, -0.1312747 , -0.06368257], dtype=float32), gc=device_type: 1, dc=[, device_type: 1], engine=u'CUDNN')
Trying example: test_relu(self=<__main__.TestRelu testMethod=test_relu>, X=array([ 0.], dtype=float32), gc=, dc=[, device_type: 1], engine=u'CUDNN')
Trying example: test_relu(self=<__main__.TestRelu testMethod=test_relu>, X=array([-0.8335939 , -0.67032146], dtype=float32), gc=device_type: 1, dc=[, device_type: 1], engine=u'CUDNN')
Trying example: test_relu(self=<__main__.TestRelu testMethod=test_relu>, X=array([ 0.05724426,  1.        ], dtype=float32), gc=device_type: 1, dc=[, device_type: 1], engine=u'')
Trying example: test_relu(self=<__main__.TestRelu testMethod=test_relu>, X=array([-0.66229254,  0.59582025, -0.85684592], dtype=float32), gc=device_type: 1, dc=[, device_type: 1], engine=u'CUDNN')
.
----------------------------------------------------------------------
Ran 1 test in 0.661s

OK

5.環境變量設置

echo $PYTHONPATH
# export PYTHONPATH=/usr/local:$PYTHONPATH
# export PYTHONPATH=$PYTHONPATH:/home/hzz/caffe2/build
echo $LD_LIBRARY_PATH
# export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

而後就能夠開心的跑caffe2上自帶的例子了。

相關文章
相關標籤/搜索