Skip to content

Instantly share code, notes, and snippets.

@viirya
Last active April 5, 2017 13:22
Show Gist options
  • Save viirya/058fda6fe8023572b196cf981909d0a7 to your computer and use it in GitHub Desktop.
Save viirya/058fda6fe8023572b196cf981909d0a7 to your computer and use it in GitHub Desktop.
Prepare environment on AWS EC2 to run Caffe or other deep learning frameworks

Basic environment

Instance: p2.xlarge

AMI ID: ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20170221

EBS volume for root: 30GB

Install ubuntu packages

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install python-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install python-pip
sudo pip install numpy

Install CUDA

Download and install CUDA from Nvidia

Install cuDNN

Download and install cuDNN from Nvidia

Make sure LD_LIBRARY_PATH is correctly set.

Fix hdf5 library issue on debian/ubuntu

Ref: BVLC/caffe#2347

Add hdf5 include path to Makefile.config.

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/

Create symlinks of lib files.

cd /usr/lib/x86_64-linux-gnu
sudo ln -s libhdf5_serial.so.8.0.2 libhdf5.so
sudo ln -s libhdf5_serial_hl.so.8.0.2 libhdf5_hl.so

Install caffe

Checkout caffe repo with git.

Setup correct variables in Makefile.config.

Make sure numpy include path is correctly set

E.g.,

PYTHON_INCLUDE := /usr/include/python2.7 \
            /usr/lib/python2.7/dist-packages/numpy/core/include \
            /usr/local/lib/python2.7/dist-packages/numpy/core/include

Add cuDNN include & lib path to INCLUDE_DIRS & LIBRARY_DIRS.

E.g.,

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /home/ubuntu/cuda/include /usr/include/hdf5/serial/
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /home/ubuntu/cuda/lib64

Compile caffe:

make all
make test
make runtest
make pycaffe

Install notebook environment

sudo pip install jupyter
sudo pip install scipy matplotlib
sudo pip install scikit-image
sudo pip install protobuf
jupyter notebook --ip="public domainname of ec2 instance"

Note

Basically, a computing machine prepared with above steps are also ready for TensorFlow installation, except for Bazel and maybe libcupti-dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment