Official Power Up Hosting Blog

Everything about Linux, Windows, and hosting ;)

I am an avid book reader, who enjoys technology as well as writing.

Share


Our Newsletter


Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Tags


Twitter


Official Power Up Hosting Blog

Guide To Install TensorFlow Python on Ubuntu 16.04 (With applications)

Apurva ChodnekarApurva Chodnekar

Introduction:

Is your mind full of tensorflow project ideas? And you want to set it up on your Ubuntu 16.04? Then you have come to the right place.

We are not just going to show you how to install tensorflow Python on Ubuntu 16.04, but we will also help you get started on it.

We will start with the most basic question that is asked any time tensorflow comes up in a conversation.

People with strong programming and development are the only ones that are aware of its meaning and how to use it.

So, what is tensorflow?

TensorFlow is an opensource software library. It uses data flow graphs to generate an output. And it is used for numerical computation.

How about this? Let's take a look at one of the tensorflow examples. It will help you understand things in much better manner.

Google mail is the perfect example. The team that worked on the development of tensorflow has even implemented tensorflow on Gmail.

Nowadays, when you get a mail from anyone we get suggestions of replies, at the end of the mail. There must have been a time when you thought,'Wow, that made emailing a lot easier'. That is the tensorflow model at work.

In the early days, it was created by google brain team for their internal usage.
tensorflow google (keyword to use)

Although a lot of people might think that with tensorflow getting started can be difficult, but it actually isn't.

There are just a few things that you have to know first before you dive into all things tensorflow.

That seems about enough to satisfy your curiosity about tensorflow for now.

You will see a few notes here and there as you go through this installation guide.

Now, that you know all about tensorflow, here are the prerequisites for installing tensorflow.

Prerequisites:

You can install tenserflow on MacOS X 10.11 or it's later version, Windows 7 or later version and on Ubuntu 14.04 and it's later versions.

  1. As we have chosen to install tensorflow on Ubuntu 16.04. You will need an Ubuntu 16.04 server. It should have at the very least a 1GB RAM. There's a reason for this particular specification.
    Don't have ubuntu 16.04 installed? This Ubuntu Server Setup
    Guide
    should help you take care of that issue.

  2. Next, you should have Python 3, as well as virtualenv, installed. Learn how to install anaconda python on ubuntu 16.04 with this guide.

  3. Lastly, you will need to have GIT installed.

Now that, that's taken care of, let's start with the installation process. You could consider it a short tensorflow python tutorial.

Steps for installing tensorflow python on ubuntu 16.04.

It's true that python and virtualenv are not the only mechanisms that can help you install tensorflow.

There are other mechanisms which can be used to install tensorflow docker is one of them. There are others as well but the virtualenve mechanism is highly recommended.

The reason for that is that virtualenv will help you create an isolated environment for tensorflow.

What it basically means is that no other python programs can affect tensorflow when it has a separate environment and it's own directories.

Step 1: Creating a new virtual environement.

To install tensorflow with python and virtualenv we have to
create a new environement for it.

So, in this step, you will create a new project directory tensorf

Mkdir ~/tensorf

After you have created the directory with make directory command let's set the current directory to tensorf.

cd ~/tensorf

Our next step will be creating a virtual environment. Let's name it tensorflow.

python3 -m venv tensorflow`

This command will create a new environment tensorflow.

Which means that while tensorflow is activated, if you create any new packages they will belong solely to this particular directory/environment.

This directory will have pip as well as a standalone version of Python.

source tensorflow/bin/activate

When you run this command your prompt will change and following change will be displayed to you.

(tensorflow)

This confirms that we have created a new virtual environment called tensorflow.

Step 2: Installing tensorflow.

Now that we have a virtual environment for tensorflow. We can install it without further ado.

(tensorflow) pip3 install --upgrade tensorflow.

This command will install python tensor flow on Ubuntu 16.04.

Step 3: Confirm the install.

You have installed tensorflow, but you still have to confirm whether it has been installed successfully.

For that, we will run a short program on the python interpreter.

(tensorflow) python

Enter the following lines of code in Python's interactive console.

# Python
import tensorflow as tnf
message = tnf.constant('Hello, brother!')
se = tnf.Session()
print(se.run(message))

Your system will display the output as below.

Output:
Hello, brother!

This output is your confirmation that tensorflow has been installed and is running with no problems.

Note: You can deactivate the virtual environment anytime you want. All you have to do is run the below command.

 deactivate

To activate it again, just do what you did before to activate it. Use the same command.

source tensorflow/bin/activate

Step 4: Tensorflow applications.

Some of you might have been just here for that part. Here's where things get a little interesting.

We will move on to the part where we figure out how to get started.

We are shortly going to see a few of tensorflow use cases in the next step. There are so many examples that are actually a part of our daily life.

Voice search, web page text translation, recommendations on popular shopping websites, etc.

Image classification is one of the tensorflow application that we will see in detail.

For image classification, we are going to use the image that has already been supplied to us. But before that, we have to clone the tensorflow model repository from GITHUB.

(tensorflow) git clone https://github.com/tensorflow/models.git

After that set the current directory as the one that contains the supplied image. In this case, it is imagenet.

(tensorflow) cd models/tutorials/image/imagenet

As we have already discussed imagenet directory contains the image of a panda that we are going to classify with the below command.

(tensorflow) python classify_image.py

Output:
giant panda, panda, panda bear, coon bear, Ailuropoda 
melanoleuca (score = 0.88493)
indri, indris, Indri indri, Indri brevicaudatus (score 
= 0.00878)
lesser panda, red panda, panda, bear cat, cat bear, 
Ailurus fulgens (score = 0.00317)
custard apple (score = 0.00149)
earthstar (score = 0.00127)`

This is how you classify an image with tensorflow.

If you want to classify another image, use the code given below.

python classify_image.py --another_image.jpg

In the above code, you can replace the another_image.jpb with the image that you want to classify.

This was just one of the applications of Tensorflow.
You can classify text with tensorflow. It can even be used for regression.

There are so many applications you just have install tensorflow and you can take a look at all of them.

Conclusion:

Isn't machine learning an amazing prospect?

Let's take a look at the machine learning definition, it is an AI which gives the system the ability to learn from their previous experiences.

This eliminates the need to reprogram them for every little thing.

With tensorflow deep learning, you can accomplish a lot. This post will guide you on your journey towards that goal of yours.

For more information, you can always refer the tensorflow wiki.

Tensorflow is continuously contributing to machine learning territory. And that is the reason you should expect more use cases/applications soon.

I am an avid book reader, who enjoys technology as well as writing.

Comments