Beginner

Introduction to TensorFlow

Discover Google's open-source machine learning framework — its origins, architecture, and why TensorFlow 2 with Keras has become the go-to platform for building and deploying AI models at scale.

What is TensorFlow?

TensorFlow is an open-source machine learning framework developed by the Google Brain team. Originally released in 2015, it has grown into one of the most widely used platforms for building, training, and deploying machine learning models. TensorFlow powers everything from Google Search and Google Photos to YouTube recommendations and Gmail Smart Reply.

Why "TensorFlow"? The name comes from tensors — multi-dimensional arrays of data — that flow through a computational graph. This graph-based computation model is what makes TensorFlow both powerful and flexible.

TensorFlow supports a wide range of tasks: image recognition, natural language processing, speech recognition, time-series forecasting, reinforcement learning, and more. It runs on CPUs, GPUs, and TPUs (Google's custom AI accelerators), and can deploy to mobile devices, web browsers, edge devices, and cloud servers.

A Brief History

Understanding TensorFlow's evolution helps explain its current design:

Year Milestone Significance
2011 DistBelief (internal) Google's first-generation deep learning system, used internally for research
2015 TensorFlow 1.0 released Open-sourced under Apache 2.0 license, graph-based execution model
2017 Keras integrated Keras became the official high-level API, simplifying model building
2019 TensorFlow 2.0 released Eager execution by default, tighter Keras integration, cleaned-up API
2023+ Keras 3 (multi-backend) Keras can now run on TensorFlow, JAX, or PyTorch backends

TensorFlow 2 vs TensorFlow 1

TensorFlow 2 was a major rewrite that addressed many pain points from TF1. If you're starting today, you'll use TF2 exclusively, but understanding the differences is useful context:

Feature TensorFlow 1 TensorFlow 2
Execution Graph mode (define-then-run) Eager mode by default (define-by-run)
API Multiple overlapping APIs (tf.layers, tf.slim, tf.contrib) Unified under tf.keras
Sessions Required tf.Session() to run operations No sessions needed
Debugging Difficult (opaque graph errors) Easy (standard Python debugging)
Learning Curve Steep Gentle (Pythonic, intuitive)

Eager Execution

Eager execution is one of the most important changes in TF2. It means operations execute immediately, returning concrete values instead of building a computational graph for later execution:

Python
import tensorflow as tf

# In TF2, operations run eagerly by default
a = tf.constant([[1, 2], [3, 4]])
b = tf.constant([[5, 6], [7, 8]])

# This immediately computes the result - no session needed!
c = tf.matmul(a, b)
print(c)
# tf.Tensor(
#   [[19 22]
#    [43 50]], shape=(2, 2), dtype=int32)

# You can even convert to NumPy seamlessly
print(c.numpy())
# [[19 22]
#  [43 50]]
Performance Note: While eager execution is great for development and debugging, TensorFlow can still use graph mode for performance. The @tf.function decorator compiles Python functions into optimized TensorFlow graphs automatically.

The Keras API

Keras is the high-level API for building and training models in TensorFlow. Originally a standalone library created by François Chollet, Keras was integrated into TensorFlow as tf.keras and is now the recommended way to build models:

Python
import tensorflow as tf
from tensorflow import keras

# Build a simple neural network in just a few lines
model = keras.Sequential([
    keras.layers.Dense(128, activation='relu', input_shape=(784,)),
    keras.layers.Dropout(0.2),
    keras.layers.Dense(10, activation='softmax')
])

# Compile with optimizer, loss, and metrics
model.compile(
    optimizer='adam',
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy']
)

# Train on data
model.fit(x_train, y_train, epochs=5, validation_split=0.2)

Keras provides three levels of API complexity to match your needs:

  • Sequential API — Simple stack of layers, perfect for most models
  • Functional API — Build complex architectures with multiple inputs/outputs and shared layers
  • Model subclassing — Full flexibility for custom training loops and research models

The TensorFlow Ecosystem

TensorFlow is more than just a training library. It is an entire ecosystem:

Component Purpose
TensorFlow Core Model building and training
TensorFlow Hub Repository of pre-trained models for transfer learning
TF Lite Deploying models on mobile and edge devices
TF.js Running models in web browsers
TF Serving Production model serving with REST/gRPC APIs
TF Extended (TFX) End-to-end ML pipeline platform
TensorBoard Visualization toolkit for training metrics, graphs, and more

Ready to Get Started?

Now that you understand what TensorFlow is and why it matters, let's install it and write your first TensorFlow code.

Next: Getting Started →