TensorFlow — A Helpful Illustrated Guide

Machine Learning (ML) is a sought-after skill in today’s automated world. Google is one of the key players in the Machine Learning space. With the growing scale and popularity of deep learning, the limitations of a single machine become more and more pronounced.

Motivation

Training a model on a single computer can take a long time—the more data you have, the longer it takes. However, deep neural network require large training data sets to reach superhuman performance levels in many tasks. Without using large training data, the quality of the models tends to be low.

  • However, who has time to wait for hours and hours only to train a single model and check its prediction accuracy?
  • Wouldn’t it be better to reduce latency by leveraging a distributed architecture that combines the power of CPUs and GPUs?

System Architecture

Google’s response to these questions is the distributed TensorFlow system. TensorFlow is a Github project published in 2015 by the Google Brain team, and described in the OSDI paper in 2016.

Here’s a short visual overview of the system architecture:

TensorFlow System Architecture

TensorFlow provides a high-level ML code library. Data scientists simply write code using the operations provided by the library. The TensorFlow system transforms this code into a data flow graph. Then it distributes the data flow graph to multiple machines and executes it in a distributed manner.

The data flow graph consists of operations and tensors.

  • Each operation transforms ingoing to outgoing tensor data.
  • Tensors are arrays or matrices of primitive data values. An example is the matrix multiplication operation. It receives two ingoing 2D matrices (tensors) and multiplies those to get the outgoing tensor.

TensorFlow provides hardware implementations for each abstract operation. The hardware implementation is denoted as a kernel. An operation may have different kernels for different hardware such as GPUs and CPUs.

Installing TensorFlow in Python

The main language to program against the TensorFlow API is Python. Here’s how you can install a CPU-only version of TensorFlow. Type this in your terminal or command-line to install a CPU-only version on your computer:

$ pip install tensorflow-cpu

If you want to have GPU support, you’ll need to install the full tensorflow distro:

$ pip install tensorflow

If you want to install TensorFlow in PyCharm, use the full installation guide available here.

Your First TensorFlow Program

Let’s assume you’ve installed TensorFlow on your computer or in your virtual environment.

Now, you can run the first hello-world program in your Python script. Here’s the program in an interactive mode:

>>> import tensorflow as tf
>>> tf.add(40, 2).numpy()
42
>>> hello = tf.constant('Hi TensorFlow!')
>>> hello.numpy()
b'Hi TensorFlow!'

Congratulations, you’ve written your first TensorFlow program!

Video Tutorial

Here’s a video provided by the TensorFlow core team—it’s a great way to start your learning journey!

And, as long as we’re on it—let’s dive into the second video in this series that’s as helpful as the first one. Thanks, TensorFlow team!

In this guide, you’ve taken your first steps towards TensorFlow proficiency. It’s a very valuable skill to have in the 21st century. Let’s dive deeper into the topic with the following resources.

Resources

The official TensorFlow repository provides the following helpful resources:

  1. TensorFlow.org
  2. TensorFlow Tutorials
  3. TensorFlow Official Models
  4. TensorFlow Examples
  5. DeepLearning.AI TensorFlow Developer Professional Certificate
  6. TensorFlow: Data and Deployment from Coursera
  7. Getting Started with TensorFlow 2 from Coursera
  8. Intro to TensorFlow for A.I, M.L, and D.L from Coursera
  9. Intro to TensorFlow for Deep Learning from Udacity
  10. Introduction to TensorFlow Lite from Udacity
  11. Machine Learning with TensorFlow on GCP
  12. TensorFlow Codelabs
  13. TensorFlow Blog
  14. Learn ML with TensorFlow
  15. TensorFlow Twitter
  16. TensorFlow YouTube
  17. TensorFlow Roadmap
  18. TensorFlow White Papers
  19. TensorBoard Visualization Toolkit