Installing TensorFlow on Ubuntu 18.04 LTS

Installing TensorFlow is not a tedious task if you have a fast internet connection. The main tool we need to have is pip, which is a package management tool used for managing and installing software packages in Python.

You can get the latest installation instructions for Linux from the following link: https://www.tensorflow.org/install/install_linux.

Let's begin installing TensorFlow through the following steps:

  1. Here is the command to install pip on Ubuntu:
$ sudo apt-get install python-pip python-dev
  1. After installing pip, you can install TensorFlow using the following command:
$ pip install tensorflow

This would install the latest and stable TensorFlow library.

If you would like a GPU version, then use this:

$ pip install tensorflow-gpu
  1. You have to execute the following command to set a bash variable called TF_BINARY_URL. This is for installing the correct binaries for our configuration. The following variable is for the Ubuntu 64 bit, Python 2.7, CPU-only version:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl

If you have an NVIDIA GPU, you may need a different binary. You may also need to install CUDA toolkit 8.0 cuDNN v5 for installing this, as shown here:

$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl
  1. After defining the bash variable, use the following command to install the binaries for Python 2:
$ sudo pip install --upgrade $TF_BINARY_URL
Check out this link for installing cuDNN: https://developer.nvidia.com/cudnn.

If everything works fine, you will get the following kind of output in the Terminal:

Installing TensorFlow

If everything has been properly installed on your system, you can check it using a simple test. Open a Python Terminal, execute the following lines, and check whether you are getting the results shown in the following screenshot:

Testing a TensorFlow installation

We will look at an explanation of the code in the next section.

Here is our hello world code in TensorFlow:

import tensorflow as tf 
hello = tf.constant('Hello, TensorFlow!') 
sess = tf.Session() 
print (sess.run(hello)) 
a = tf.constant(12) 
b = tf.constant(34) 
print(sess.run(a+b)) 

The output of the preceding code is as shown in the preceding screenshot. In the next section, we will look at a few important concepts of TensorFlow.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.131.72