Skip to content

Instantly share code, notes, and snippets.



Last active May 24, 2017
What would you like to do?
Boostrap Scripts to Install and Test Setup for Deep Learning Applications

Boostrap Scripts to Install and Test Setup for Deep Learning Applications

This gist is simply a set of scripts to install and test everything you need to get started with Deep Learning. This includes:

  • TensorFlow
  • Theano
  • Keras
  • CUDA Toolkit
  • Misc. linux Tools like tmux.

How to use

  • Assuming you already have a newly created EC2 GPU instance, and are able to SSH into it.

  • Copy, and on the machine.

  • Run chmod +x *.sh to make the .sh files executable

  • Run sudo ./ and go have a cup of tea while it installs everything for you

    • If a pink screen pops up mentioning "A new version of /boot/grub/menu.lst is available", choose "Keep local version" and select OK.
  • When the message to restart system comes up, just restart with sudo shutdown -r 0

  • After restart, run ./

    • If everything has gone correct, then you will see output matching the expected output (in green). You are all set to get started!
    • In case of errors, please ping me at @navinpai on twitter or email at navin[at]fiftheye[dot]in



Thanks and Have Fun!

Navin "M@dMAx" Pai (@navinpai)

apt-get update
apt-get -y dist-upgrade
apt-get install -y gcc g++ gfortran build-essential git wget tmux linux-image-extra-`uname -r` linux-generic linux-image-generic libopenblas-dev python-dev python-pip python-nose python-numpy python-scipy
# Bleeding edge Theano
pip install --upgrade --no-deps git+git://
# Install Tensorflow
sudo pip install six --upgrade --target="/usr/lib/python2.7/dist-packages"
pip install --upgrade
# Keras v.1.0.7
pip install --upgrade --no-deps keras==1.0.7
# Scikit-Learn
pip install -U scikit-learn
curl -fsSL -O
dpkg -i cuda-repo-ubuntu1404_7.0-28_amd64.deb
apt-get update
apt-get install -y cuda
echo -e "\nexport PATH=/usr/local/cuda/bin:$PATH\n\nexport LD_LIBRARY_PATH=/usr/local/cuda/lib64\n\nexport CUDA_HOME=/usr/local/cuda\n\nexport PS1='\[\033[0;32m\]\u@\[\033[0;33m\]D33P_L34RN:\[\033[36m\]\W\[\033[0m\] \$ '" >> .bashrc
curl -fsSL -O
tar xvzf cudnn-7.0-linux-x64-v4.0-prod.tgz
cp cuda/include/cudnn.h /usr/local/cuda/include
cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
# Make Theano use GPU by default
echo -e "\n[global]\nfloatX=float32\ndevice=gpu\n[mode]=FAST_RUN\n\n[nvcc]\nfastmath=True\n\n[cuda]\nroot=/usr/local/cuda" >> ~/.theanorc
# Reboot system and run
echo -e '\E[33;92m'"Reboot System (sudo shutdown -r 0) and run ./"; tput sgr0
# Test CUDA install
echo -e '\E[33;92m'"TEST CUDA INSTALL"; tput sgr0 ~
cd NVIDIA_CUDA-7.5_Samples/1_Utilities/deviceQuery
echo -e '\E[33;92m'"SHOULD PRINT Result = PASS ABOVE THIS LINE"; tput sgr0
# Test Theano GPU usage
echo -e '\E[33;92m'""; tput sgr0
cd ~
echo -e '\E[33;92m'"SHOULD PRINT Used the gpu ABOVE THIS LINE"; tput sgr0
# Test Theano CDNN usage
echo -e '\E[33;92m'"TEST Theano CDNN USAGE"; tput sgr0
python -c 'from theano.sandbox.cuda.dnn import version; print(version())'
echo -e '\E[33;92m'"SHOULD PRINT (4007, 4007) ABOVE THIS LINE"; tput sgr0
# Run MNIST on TensorFlow
echo -e '\E[33;92m'"TEST TENSORFLOW (Might take a while...)"; tput sgr0
python -m tensorflow.models.image.mnist.convolutional
echo -e '\E[33;92m'"Should Print Validation and Test Error numbers ABOVE THIS LINE"; tput sgr0
echo -e '\E[1;33;92m'"If No errors Seen, then you are done! Have fun! :) - M@dMAx"; tput sgr0
from theano import function, config, shared, sandbox
import theano.tensor as T
import numpy
import time
vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
iters = 1000
rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], T.exp(x))
t0 = time.time()
for i in range(iters):
r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (r,))
if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):
print('Used the cpu')
print('Used the gpu')

This comment has been minimized.

Copy link
Owner Author

@navinpai navinpai commented Sep 21, 2016

If you get the following error on running python -m tensorflow.models.image.mnist.convolutional:

Traceback (most recent call last): File "/usr/lib/python2.7/", line 151, in _run_module_as_main mod_name, loader, code, fname = _get_module_details(mod_name) File "/usr/lib/python2.7/", line 101, in _get_module_details loader = get_loader(mod_name) File "/usr/lib/python2.7/", line 464, in get_loader return find_loader(fullname) File "/usr/lib/python2.7/", line 474, in find_loader for importer in iter_importers(fullname): File "/usr/lib/python2.7/", line 430, in iter_importers __import__(pkg) File "/usr/local/lib/python2.7/dist-packages/tensorflow/", line 23, in <module> from tensorflow.python import * File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/", line 98, in <module> from tensorflow.python.platform import test File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/", line 63, in <module> from tensorflow.python.framework import test_util File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/", line 43, in <module> from tensorflow.python.platform import googletest File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/", line 32, in <module> from tensorflow.python.platform import benchmark # pylint: disable=unused-import File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/", line 112, in <module> class Benchmark(six.with_metaclass(_BenchmarkRegistrar, object)): File "/usr/lib/python2.7/dist-packages/", line 617, in with_metaclass return meta("NewBase", bases, {}) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/", line 107, in __new__ if not newclass.is_abstract(): AttributeError: type object 'NewBase' has no attribute 'is_abstract'


sudo pip install six --upgrade --target="/usr/lib/python2.7/dist-packages"
and then try again

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