Did you know that you can navigate the posts by swiping left and right?

Installing TensorFlow on Ubuntu 17.04

23 Jun 2017 . category: tech . Comments
#tensorflow #ubuntu #17.04 #machinelearning

I recently installed TensorFlow 1.3 with GPU support on my Laptop running Ubuntu 17.04. I was very dissatisfied by the existing guides and tutorials, being either wrong or too difficult to understand. My guide hopefully does a better job at helping you setup TensorFlow properly.

While this guide was written for 17.04, it should work on every semi-new Ubuntu version.

Installing TensorFlow without GPU support

If you are only training small networks and have a fast CPU, you might not even notice the speed gain from GPU support. When running TensorFlow with GPU-support, it takes time to copy the training-data onto GPU-memory. In my experience, very small networks (like those needed for the MNIST Tutorials from Google), train faster on CPU than on GPU. To install TensorFlow without GPU-support, type:


pip3 install tensorflow

and you’re good to go.

You can always install TF with GPU-support later, just uninstall CPU-TensorFlow using pip3 uninstall tensorflow, and continue with guide from here.

Installing TensorFlow with GPU support

Graphics card

You will need a NVIDIA GPU with CUDA Compute Capability 3.0 or higher. See supported cards here. To check if you have the correct driver, open Ubuntu’s utility program Software & Updates. The tab Additional drivers shows you which driver you have installed. Make sure you are using the latest NVIDIA driver listed there. This should be version 375.

Required Files

Download both, don’t install them yet.

  • CUDA 8.0: Select Linux -> x86_64 -> Ubuntu -> 16.04 -> deb (local)

  • cuDNN v6: Make sure to get version 6 and not the newest one! You will need to sign up for NVIDIA’s developer program to download this. The file you need is cuDNN v6 Library for Linux.

Setting up

Type:


sudo apt install linux-headers-$(uname -r)

to install kernel headers and development packages.

Installing CUDA 8.0

Change into the folder with the files you downloaded (probably ~/Downloads) and run:


sudo dpkg -i <name-of-cuda-file>.deb # install the downloaded package
sudo apt update # update your package list
sudo apt install cuda-8-0 # install cuda

This will install CUDA into the folder /usr/local/cuda-8.0.

Install cuDNN 6

Again, change into the folder with the downloaded files and run:


tar -xvzf <name-of-cuDNN-file>.tgz # extract the downloaded file
sudo mv cuda /usr/local/ # move the file into the correct folder

Now we have to add this path as a global variable to our default shell. If you haven’t installed a different shell (like zsh), your default shell is bash. To open the config file of bash:


gedit ~/.bashrc

And paste this at the end of the file: export LD_LIBRARY_PATH=/usr/local/cuda/lib64/. Save the file, then load the new configuration into bash:


source ~/.bashrc

If you have installed a different shell, you have to use the corresponding config file (e.g. ~/.zshrc for zsh).

NVIDIA CUDA Profile Tools


sudo apt install libcupti-dev

The Profile Tools can help you understand what is going on inside your GPU.

Installing TensorFlow

Now that CUDA and cuDNN are set up, we can install TensorFlow.


pip3 install tensorflow-gpu

(optional) If you want to isolate this TensorFlow installation from other python development on your machine, you should first set up a virtual environment using Virtualenv.

Checking the installation

To check if TensorFlow is installed correctly, open a python shell (type python3) and run:


import tensorflow
print(tensorflow.__version__)

TensorFlow should be imported without errors and you should see 1.3 being printed out.

Getting started with TensorFlow

If you are new to the TensorFlow world and need some guidance, here are some links that I used to teach myself the basics:

  • A 3 hour talk by a Google employee. Listen to the talk and pause to implement the networks he is talking about in TensorFlow. If you are stuck, there is a codelab with more explanations and links to the code being used.

  • A Stanford course. This is a student taught course complete with notes and assignments.


Me

Simon Böhm | Computer Science student at KIT