INSTALL TENSORFLOW 1.2.1 for PYTHON 3.5 ON UBUNTU 16, CUDA 8.0, CUDNN 5.1.

1. INSTALL CUDA

a. Update/Install Nvidia Drivers:
$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt update (re-run if any warning/error messages)
$ sudo apt-get install nvidia- (press tab to see latest). 375 (do not use 378, may cause login loops)

b. Download suitable CUDA version:
Navigate to https://developer.nvidia.com/cuda-downloads.

c. Install CUDA:
$ sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb (this is the deb file you’ve downloaded)
$ sudo apt-get update
$ sudo apt-get install cuda

$ export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
$ export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64\${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

d. Test CUDA:
$ cd /usr/local/cuda-8.0/samples/5_Simulations/nbody
$ sudo make
$ ./nbody

2. INSTALL CUDNN

a. Download suitable CUDNN version:
We install CuDNN 5.1 as currently Tensoflow doesn’t support CuDNN 6.
Navigate to https://developer.nvidia.com/cudnn

b. Extract than copy cudnn to cuda:
$ tar -xzvf cudnn-8.0-linux-x64-v5.1.tgz # after this step, it will appear a folder name: cuda
$ sudo cp cuda/include/cudnn.h /usr/local/cuda/include
$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
$ sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

3. INSTALL ANACONDA and ENVIRONMENT

a. Download and Install ANACONDA
wget https://repo.continuum.io/archive/Anaconda3-4.3.1-Linux-x86_64.sh -O “anaconda-install.sh”
bash anaconda-install.sh -b
cat >> ~/.bashrc << ‘EOF’
export PATH=$HOME/anaconda3/bin:${PATH}
EOF
source .bashrc
conda upgrade -y –all

b. Create ENVIRONMENT(where contains the packages: python, pip, tensorflow, opencv, …)
conda create -n <NAME OF ENVIRONMENT>

c. Install suitable PYTHON into package
conda install –name <NAME OF ENVIRONMENT> python=3.5

4. INSTALL TENSORFLOW

a. Prepare TensorFlow Dependencies and Required Packages
$ sudo apt-get install libcupti-dev

b. Install TENSORFLOW
source activate <NAME OF ENVIRONMENT>
pip install –ignore-installed –upgrade \ https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.2.1-cp36-cp36m-linux_x86_64.whl
(WINDOWS: pip install –ignore-installed –upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.2.1-cp35-cp35m-win_amd64.whl)
(pip install tensorflow-gpu)
(pip install –ignore-installed –upgrade \ https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.2.1-cp35-cp35m-linux_x86_64.whl)
(pip install –ignore-installed –upgrade \ https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.2.1-cp27-none-linux_x86_64.whl)

5. INSTALL OTHER PACKAGES

c. Install other packages
conda install -n <NAME OF CHANNEL> <NAME OF PACKAGE>=<VERSION OF PACKAGE>
conda install -c conda-forge numpy=1.13.1 -y
conda install -c conda-forge matplotlib=2.0.2 -y
conda install -c menpo opencv3=3.2.0 -y
(conda install -c conda-forge opencv -y
conda install -c conda-forge/label/broken opencv -y)
conda install -c conda-forge pandas=0.20.3 -y
conda install -c conda-forge scipy=0.19.1 -y
conda install -c conda-forge pillow=4.2.1 -y
conda install -c conda-forge scikit-learn=0.18.2 -y
conda install -c conda-forge scikit-image=0.13.0 -y
#conda install -c conda-forge tensorflow=1.2.0 -y
conda install -c conda-forge ipython -y
conda install -c conda-forge jupyter -y
conda install -c conda-forge spyder -y

d. Update conda
conda update conda
conda update <NAME OF PACKAGE>

d. Remove a package in an environment:
conda remove –name <NAME OF ENVIRONMENT> <NAME OF PACKAGE>

e. Remove an environment:
conda remove –name <NAME OF ENVIRONMENT> –all

 

VERIFY SUCCESSFUL INSTALLATION
To check whether TENSORFLOW runs or not and runs on GPU or not?
To find out which devices your operations and tensors are assigned to, create the session with log_device_placement configuration option set to True.

# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name=’a’)
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name=’b’)
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))

You should see the following output:

Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: Tesla K40c, pci bus
id: 0000:05:00.0
b: /job:localhost/replica:0/task:0/gpu:0
a: /job:localhost/replica:0/task:0/gpu:0
MatMul: /job:localhost/replica:0/task:0/gpu:0
[[ 22. 28.]
[ 49. 64.]]

References:
https://blog.slavv.com/the-1700-great-deep-learning-box-assembly-setup-and-benchmarks-148c5ebe6415

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s