caffe2--ubuntu16.04--14.04--install

Install

Welcome to Caffe2! Get started with deep learning today by following the step by step guide on how to download and install Caffe2.

Select your preferred platform and install type.

Build Status

This build is confirmed for:

  • Ubuntu 14.04
  • Ubuntu 16.04

Required Dependencies#

1
2
3
4
5
6
7
8
9
10
11
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 

Optional GPU Support#

If you plan to use GPU instead of CPU only, then you should install NVIDIA CUDA 8 and cuDNN v5.1 or v6.0, a GPU-accelerated library of primitives for deep neural networks. NVIDIA’s detailed instructions or if you’re feeling lucky try the quick install set of commands below.

Update your graphics card drivers first! Otherwise you may suffer from a wide range of difficult to diagnose errors.

For Ubuntu 14.04

1
2
3
4
5
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

For Ubuntu 16.04

1
2
3
4
5
sudo apt-get update && sudo apt-get install wget -y --no-install-recommends
wget "http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb"
sudo dpkg -i cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda
Install cuDNN (all Ubuntu versions)#

Version 5.1

1
2
3
4
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

Version 6.0 Visit NVIDIA’s cuDNN download to register and download the archive. Follow the same instructions above switching out for the updated library.

Optional Dependencies#

Note libgflags2 is for Ubuntu 14.04. libgflags-dev is for Ubuntu 16.04.

1
2
# for Ubuntu 14.04
sudo apt-get install -y --no-install-recommends libgflags2
1
2
# for Ubuntu 16.04
sudo apt-get install -y --no-install-recommends libgflags-dev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# for both Ubuntu 14.04 and 16.04
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 \ future \ graphviz \ hypothesis \ jupyter \ matplotlib \ pydot python-nvd3 \ pyyaml \ requests \ scikit-image \ scipy \ setuptools \ six \ tornado 

Clone & Build#

1
2
3
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" 

Run this command below to test if your GPU build was a success. You will get a test output either way, but it will warn you at the top of the output if CPU was used instead along with other errors like missing libraries.

1
python -m caffe2.python.operator_test.relu_op_test

Environment Variables#

These environment variables may assist you depending on your current configuration. When using the install instructions above on the AWS Deep Learning AMI you don’t need to set these variables. However, our Docker scripts built on Ubuntu-14.04 or NVIDIA’s CUDA images seem to benefit from having these set. If you ran into problems with the build tests above then these are good things to check. Echo them first and see what you have and possibly append or replace with these directories. Also visit the Troubleshooting section.

1
2
3
4
5
echo $PYTHONPATH
# export PYTHONPATH=/usr/local:$PYTHONPATH
# export PYTHONPATH=$PYTHONPATH:/home/ubuntu/caffe2/build
echo $LD_LIBRARY_PATH # export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH 

Setting Up Tutorials & Jupyter Server#

If you’re running this all on a cloud computer, you probably won’t have a UI or way to view the IPython notebooks by default. Typically, you would launch them locally with ipython notebook and you would see a localhost:8888 webpage pop up with the directory of notebooks running. The following example will show you how to launch the Jupyter server and connect to remotely via an SSH tunnel.

First configure your cloud server to accept port 8889, or whatever you want, but change the port in the following commands. On AWS you accomplish this by adding a rule to your server’s security group allowing a TCP inbound on port 8889. Otherwise you would adjust iptables for this.

security group screenshot

Next you launch the Juypter server.

1
jupyter notebook --no-browser --port=8889

Then create the SSH tunnel. This will pass the cloud server’s Jupyter instance to your localhost 8888 port for you to use locally. The example below is templated after how you would connect AWS, where your-public-cert.pem is your own public certificate and ubuntu@super-rad-GPU-instance.compute-1.amazonaws.com is your login to your cloud server. You can easily grab this on AWS by going to Instances > Connect and copy the part after ssh and swap that out in the command below.

1
ssh -N -f -L localhost:8888:localhost:8889 -i "your-public-cert.pem" ubuntu@super-rad-GPU-instance.compute-1.amazonaws.com

Troubleshooting#

PYTHON ERRORS 
Python versionPython is core to run Caffe2. We currently require Python2.7Ubuntu 14.04 and greater have Python built in by default, and that can be used to run Caffe2. To check your version: python --version
SolutionIf you want the developer version of python, you could install the dev package for Python: sudo apt-get install python-dev
Python environmentYou may have another version of Python installed or need to support Python version 3 for other projects.
SolutionTry virtualenv or Anaconda. The Anaconda platform provides a single script to install many of the necessary packages for Caffe2, including Python. Using Anaconda is outside the scope of these instructions, but if you are interested, it may work well for you.
pip versionIf you plan to use Python with Caffe2 then you need pip.
Solutionsudo apt-get install python-pip and also try using pip2 instead of pip.
BUILDING FROM SOURCE 
OS versionCaffe2 requires Ubuntu 14.04 or greater.
gitWhile you can download the Caffe2 source code and submodules directly from GitHub as a zip, using git makes it much easier.
Solutionsudo apt-get install git
protobufYou may experience an error related to protobuf during the make step.
SolutionMake sure you’ve installed protobuf in both of these two ways: sudo apt-get install libprotobuf-dev protobuf-compiler && sudo pip install protobuf
libgflags2 errorThis optional dependency is for Ubuntu 14.04.
SolutionUse apt-get install libgflags-dev for Ubuntu 16.04.
GPU SUPPORT 
GPU errorsUnsupported GPU or wrong version
SolutionYou need to know the specific deb for your version of Linux. sudo dpkg -i cuda-repo-<distro>_<version>_<architecture>.debRefer to NVIDIA’s installation guide.
Build issuesBe warned that installing CUDA and cuDNN will increase the size of your build by about 4GB, so plan to have at least 12GB for your Ubuntu disk size.
CAFFE2 PYTHON 
Module not foundVerify that Caffe2 was installed correctly
SolutionRun the following: python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"An output of Success means you are ready to with Caffe2 - congratulations! An output of Failure usually means you have not installed one of the dependencies correctly.
Dependencies missingIt’s possible you’re trying to run something that was using an optional dependency.
Solutionsudo pip install setuptools flask jupyter matplotlib scipy pydot tornado python-nvd3 scikit-image pyyaml
matplotlib errorSometimes you need setuptools first: sudo pip install -U pip setuptools && sudo pip install matplotlib
model downloader errorIf you need to run it as sudo (because it’s trying to install the model in /usr/local/caffe2…), then PYTHONPATH might not be visible in that context.
Solutionsudo visudo then add this line: Defaults env_keep += "PYTHONPATH"
“AttributeError: ‘module’ object has no attribute ‘MakeArgument’”Occurs when calling core.CreateOperator
SolutionCheck your install directory (/usr/local/), and remove the folder /caffe2/python/utils
OTHER ERRORS 
libdc1394 errorfor some reason once opencv is installed you may get errors with libdc1394
Solutionln /dev/null /dev/raw1394 but that’s not persistent so try sh -c 'ln -s /dev/null /dev/raw1394' or when instantiating the container use: --device /dev/null:/dev/raw1394
caffe2_pybind11_state_gpuWARNING:root:Debug message: No module named caffe2_pybind11_state_gpu
Solutionignore if you’re using CPU-only
Python kernel crashingThis happens when you try to call Jupyter server directly (like in a Docker container).
SolutionUse sh -c "jupyter notebook ..." to get around this problem.
Exception: “dot” not found in pathThis happens in some of the tutorials when graphing.
SolutionMake sure you have graphviz and pydotsudo apt-get install python-pydot and sudo pip install graphvizor brew install these to fix the problem.

Dependencies#

Try to keep the system and python dependencies at the same version. We’ve encountered issues when the python version is more updated than the system version or vice versa.

SYSTEM DEPENDENCIES 
cmake 
git 
gflags 
glog: Google Logging Module 
NumPy 
protobuf: Google Protocol Buffersversion 3.2.0
Build tools for C++ 11Xcode CLTs & automake (mac/iOS), build-essential (linux), Visual Studio (win), Android Studio (droid)
PYTHON DEPENDENCIES 
gflags 
glog: Google Logging Module 
NumPy 
protobuf: Google Protocol Buffersversion 3.2.0

Strictly speaking, the core dependencies above are all you need to run the core Caffe2 successfully. However, for real-world deep learning (e.g., image processing, mathematical operations, etc), there are other dependencies that you will want to install in order to experience the full features of Caffe2.

OPTIONAL SYSTEM DEPENDENCIES 
cuDNNif using GPU, this is needed for Caffe2’s cuDNN operators
Eigen 3 
LevelDB 
Nvidia CUDAv6.5 or greater
OpenCVfor image-related operations; requires leveldb <= v1.19
OpenMPIfor MPI-related Caffe2 operators
RocksdBfor Caffe2’s RocksDB IO backend
ZeroMQneeded for Caffe2’s ZmqDB IO backend (serving data through a socket)
PYTHON OPTIONAL DEPENDENCIES 
There are also various Python libraries that will be valuable in your experience with Caffe2. Many of these are required to run the tutorials. 
Flask 
Graphviz 
Hypothesis 
Jupyterfor the Jupyter Notebook
LevelDB 
lmdb 
Matplotlib 
Pydot 
Python-nvd3 
pyyaml 
requests 
Scikit-Image 
SciPy 
setuptools 
Tornado 
ZeroMQ 
WHAT’S IN THIRD PARTY? 
Whether building from source or installing from the Python wheel, you also get complimentary tools installed as well. 
Android cmake 
benchmark 
cnmem 
cub 
eigen 
googletest 
ios-cmake 
nccl 
nervanagpu 
NNPACKrequires ninja and confu to build
Google Protocol Buffers (protobuf) 
pybind11 

转载于:https://www.cnblogs.com/leoking01/p/7150756.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值