Introduction to the Python Deep Learning Library TensorFlow

TensorFlow is a Python library for fast numerical computing created and released by Google.

It is a foundation library that can be used to create Deep Learning models directly or by using wrapper libraries that simplify the process built on top of TensorFlow.

In this post you will discover the TensorFlow library for Deep Learning.

Let’s get started.

Introduction to the Python Deep Learning Library TensorFlow

Introduction to the Python Deep Learning Library TensorFlow
Photo by Nicolas Raymond, some rights reserved.

What is TensorFlow?

TensorFlow is an open source library for fast numerical computing.

It was created and is maintained by Google and released under the Apache 2.0 open source license. The API is nominally for the Python programming language, although there is access to the underlying C++ API.

Unlike other numerical libraries intended for use in Deep Learning like Theano, TensorFlow was designed for use both in research and development and in production systems, not least RankBrain in Google search and the fun DeepDream project.

It can run on single CPU systems, GPUs as well as mobile devices and large scale distributed systems of hundreds of machines.

How to Install TensorFlow

Installation of TensorFlow is straightforward if you already have a Python SciPy environment.

TensorFlow works with Python 2.7 and Python 3.3+. You can follow the Download and Setup instructions on the TensorFlow website. Installation is probably simplest via PyPI and specific instructions of the pip command to use for your Linux or Mac OS X platform are on the Download and Setup webpage.

There are also virtualenv and docker images that you can use if you prefer.

To make use of the GPU, only Linux is supported and it requires the Cuda Toolkit.

Your First Examples in TensorFlow

Computation is described in terms of data flow and operations in the structure of a directed graph.

  • Nodes: Nodes perform computation and have zero or more inputs and outputs. Data that moves between nodes are known as tensors, which are multi-dimensional arrays of real values.
  • Edges: The graph defines the flow of data, branching, looping and updates to state. Special edges can be used to synchronize behavior within the graph, for example waiting for computation on a number of inputs to complete.
  • Operation: An operation is a named abstract computation which can take input attributes and produce output attributes. For example, you could define an add or multiply operation.

Computation with TensorFlow

This first example is a modified version of the example on the TensorFlow website. It shows how you can create a session, define constants and perform computation with those constants using the session.

Running this example displays:

Linear Regression with TensorFlow

This next example comes from the introduction on the TensorFlow tutorial.

This examples shows how you can define variables (e.g. W and b) as well as variables that are the result of computation (y).

We get some sense of TensorFlow separates the definition and declaration of the computation from the execution in the session and the calls to run.

Running this example prints the following output:

You can learn more about the mechanics of TensorFlow in the Basic Usage guide.

More Deep Learning Models

Your TensorFlow installation comes with a number of Deep Learning models that you can use and experiment with directly.

Firstly, you need to find out where TensorFlow was installed on your system. For example, you can use the following Python script:

For example, this could be:

Change to this directory and take note of the models subdirectory. Included are a number of deep learning models with tutorial-like comments, such as:

  • Multi-threaded word2vec mini-batched skip-gram model.
  • Multi-threaded word2vec unbatched skip-gram model.
  • CNN for the The CIFAR-10 network.
  • Simple, end-to-end, LeNet-5-like convolutional MNIST model example.
  • Sequence-to-sequence model with an attention mechanism.

Also check the examples directory as it contains an example using the MNIST dataset.

There is also an excellent list of tutorials on the main TensorFlow website. They show how to use different network types, different datasets and how to use the framework in various different ways.

Finally, there is the TensorFlow playground where you can experiment with small networks right in your web browser.

Need help with Deep Learning in Python?

Take my free 2-week email course and discover MLPs, CNNs and LSTMs (with sample code).

Click to sign-up now and also get a free PDF Ebook version of the course.

Start Your FREE Mini-Course Now!

TensorFlow Resources

More Resources


In this post you discovered the TensorFlow Python library for deep learning.

You learned that it is a library for fast numerical computation, specifically designed for the types of operations that are required in the development and evaluation of large deep learning models.

Do you have any questions about TensorFlow or about this post? Ask your questions in the comments and I will do my best to answer them.

Frustrated With Your Progress In Deep Learning?

Deep Learning with Python

 What If You Could Develop A Network in Minutes

…with just a few lines of Python

Discover how in my new Ebook: Deep Learning With Python

It covers self-study tutorials and end-to-end projects on topics like:
Multilayer PerceptronsConvolutional Nets and Recurrent Neural Nets, and more…

Finally Bring Deep Learning To
Your Own Projects

Skip the Academics. Just Results.

Click to learn more.

8 Responses to Introduction to the Python Deep Learning Library TensorFlow

  1. Jatin November 29, 2016 at 7:33 pm #

    This was great help.

    Can you post some more tutorials using tensor-flow.


  2. Amit Kumar February 7, 2017 at 9:58 pm #

    print this line is syntactically incorrect. print is a method so should have an opening and closing bracket.

    • Jason Brownlee February 8, 2017 at 9:35 am #

      Thanks Amit, fixed.

    • Asesh April 20, 2017 at 5:49 pm #

      What if it’s Python 2.7? Isn’t the print statement without bracket valid?

      • Jason Brownlee April 21, 2017 at 8:33 am #

        The brackets are ignored/do nothing, and it makes the same code work in Python3.

  3. Walid Ahmed August 9, 2017 at 1:18 am #

    Hi Jason

    I could not find a models folder in my Tensorflow installation.
    Can you please help?

    • Jason Brownlee August 9, 2017 at 6:38 am #

      I think they have been removed from the most recent release.

Leave a Reply