Tensorflow Installtion Ubuntu16.4
Tensorflow Installtion Ubuntu16.4
Tensorflow Installtion Ubuntu16.4
TensorFlow is an open-source machine learning software built by Google to train neural networks.
TensorFlow's neural networks are expressed in the form of stateful dataflow graphs. Each node in
the graph represents the operations performed by neural networks on multi-dimensional arrays.
These multi-dimensional arrays are commonly known as "tensors", hence the name TensorFlow.
TensorFlow is a deep learning software system. TensorFlow works well for information retrieval, as
demonstrated by Google in how they do search ranking in their machine-learning artificial
intelligence system, RankBrain. TensorFlow can perform image recognition, as shown in Google's
Inception, as well as human language audio recognition. It's also useful in solving other problems
not specific to machine learning, such as partial differential equations.
The TensorFlow architecture allows for deployment on multiple CPUs or GPUs within a desktop,
server or mobile device. There are also extensions for integration with CUDA, a parallel computing
platform from Nvidia. This gives users who are deploying on a GPU direct access to the virtual
instruction set and other elements of the GPU that are necessary for parallel computational tasks.
In this tutorial, you'll install TensorFlow's "CPU support only" version. This installation is ideal for
people looking to install and use TensorFlow, but who don't have an Nvidia graphics card or don't
need to run performance-critical applications.
You can install TensorFlow several ways. Each method has a different use case and development
environment:
• Python and Virtualenv: In this approach, you install TensorFlow and all of the packages
required to use TensorFlow in a Python virtual environment. This isolates your TensorFlow
environemnt from other Python programs on the same machine.
• Native pip: In this method, you install TensorFlow on your system globally. This is
recommended for people who want to make TensorFlow available to everyone on a multi-
user system. This method of installation does not isolate TensorFlow in a contained
environment and may interfere with other Python installations or libraries.
• Docker: Docker is a container runtime environment and completely isolates its contents
from preexisting packages on your system. In this method, you use a Docker container that
contains TensorFlow and all of its dependencies. This method is ideal for incorporating
TensorFlow into a larger application architecture already using Docker. However, the size of
the Docker image will be quite large.
In this tutorial, you'll install TensorFlow in a Python virtual environment with virtualenv. This
approach isolates the TensorFlow installation and gets things up and running quickly. Once you
complete the installation, you'll validate your installation by running a short TensorFlow program
and then use TensorFlow to perform image recognition.
Prerequisites
Before you begin this tutorial, you'll need the following:
• One Ubuntu 16.04 server with at least 1GB of RAM set up by following the Ubuntu 16.04
initial server setup guide, including a sudo non-root user and a firewall. You'll need at least
1GB of RAM to successfully perform the last example in this tutorial.
• Python 3.3 or higher and virtualenv installed. Follow How to Install Python 3 on
Ubuntu 16.04 to configure Python and virtualenv.
• Git installed, which you can do by following How To Install Git on Ubuntu 16.04. You'll use
this to download a repository of examples.
Then create a new virtual environment called tensorflow-dev. Run the following command to
create the environment:
python3 -m venv tensorflow-dev
This creates a new tensorflow-dev directory which will contain all of the packages that you
install while this environment is activated. It also includes pip and a standalone version of Python.
Once activated, you will see something similar to this in your terminal:
(tensorflow-dev)username@hostname:~/tf-demo $
...
Successfully installed bleach-1.5.0 enum34-1.1.6 html5lib-0.9999999 markdown-
2.6.9 numpy-1.13.3 protobuf-3.5.0.post1 setuptools-38.2.3 six-1.11.0 tensorflow-
1.4.0 tensorflow-tensorboard-0.4.0rc3 werkzeug-0.12.2 wheel-0.30.0
If you'd like to deactivate your virtual environment at any time, the command is:
deactivate
To reactivate the environment later, navigate to your project directory and run source
tensorflow-dev/bin/activate.
Now, that you have installed TensorFlow, let's make sure the TensorFlow installation works.
This is the prompt for the Python interpreter, and it indicates that it's ready for you to start entering
some Python statements.
First, type this line to import the TensorFlow package and make it available as the local variable tf.
Press ENTER after typing in the line of code:
import tensorflow as tf
Next, add this line of code to set the message "Hello, world!":
hello = tf.constant("Hello, world!")
Then create a new TensorFlow session and assign it to the variable sess:
sess = tf.Session()
This tells you that that you have an instruction set that has the potential to be optimized for better
performance with TensorFlow. If you see this, you can safely ignore it and continue.
Finally, enter this line of code to print out the result of running the hello TensorFlow session
you've constructed in your previous lines of code:
print(sess.run(hello))
This indicates that everything is working and that you can start using TensorFlow to do something
more interesting.
Exit the Python interactive console by pressing CTRL+D.
Now let's use TensorFlow's image recognition API to get more familiar with TensorFlow.
You will see the following output as Git checks out the repository into a new folder called models:
Output
Cloning into 'models'...
remote: Counting objects: 8785, done.
remote: Total 8785 (delta 0), reused 0 (delta 0), pack-reused 8785
Receiving objects: 100% (8785/8785), 203.16 MiB | 24.16 MiB/s, done.
Resolving deltas: 100% (4942/4942), done.
Checking connectivity... done.
You have classified your first image using the image recognition capabilities of TensorFlow.
If you'd like to use another image, you can do this by adding the -- image_file argument to
your python3 classify_image.py command. For the argument, you'd pass in the absolute
path of the image file.
Conclusion
You've installed TensorFlow in a Python virtual environment and validated that TensorFlow works
by running a couple of examples. You now possess tools that make it possible for you to explore
additional topics including Convolutional Neural Networks and Word Embeddings.
TensorFlow's programmer's guide is a great resource and reference for TensorFlow development.
You can also explore Kaggle, a competitive environment for practical application of machine
learning concepts that pit you against other machine learning, data science, and statistics
enthusiasts. They have an excellent wiki where you can see and share solutions, some of which are
on the cutting edge of statistical and machine learning techniques.