Learn TensorFlow

Google's end-to-end platform for training and deploying ML models

24 lessons · 5 hours · 4 levels · covers TensorFlow 2.20

TensorFlow is an open-source machine learning platform with tensors, automatic differentiation, graph compilation and a mature deployment story: SavedModel, TF Serving, LiteRT (TFLite) for mobile and TPU support. Since 2.16 its high-level API is Keras 3. Learning it matters for maintaining the large body of production TF code and for its serving and on-device tooling.

Before you start

TensorFlow builds on these; the tree links to the exact lessons you need.

How deep do you want to go?

1. EssentialsRead and write simple code, do the everyday basics8 lessons · 1 hour in total
2. PracticalUse it productively at work, with the usual idioms15 lessons · 3 hours in total
3. AdvancedThe less common features, performance and trade-offs20 lessons · 4 hours in total
4. ExpertInternals and the edge cases experts know24 lessons · 5 hours in total

The TensorFlow tree

TensorFlowTensors and eager executionTensors and eagerexecutionTensor math and broadcastingTensor math andbroadcastingIndexing, gathering and reshapingIndexing, gatheringand reshapingVariablesVariablesGradients with GradientTapeGradients withGradientTapeBuilding models with tf.kerasBuilding models withtf.kerastf.data input pipelinestf.data input pipelinesDevices and GPUsDevices and GPUstf.function and tracingtf.function andtracingCustom training loopsCustom trainingloopsFast input pipelinesFast input pipelinesSavedModel exportSavedModel exportTraining checkpointsTraining checkpointsTensorBoardTensorBoardStrings, ragged tensors and textStrings, raggedtensors and textThe ndarrayThe ndarrayListsListsVectorized arithmeticVectorized arithmeticIndexing and slicingIndexing and slicingfor and while loopsfor and while loopsFunctions as objects, lambdas and closuresFunctions as objects,lambdas and closur…
Essentials and Practical shown (15 of 24 lessons); the full list is below. Click a lesson to read it.

All 24 lessons, in order

Tensors & variables

  1. Tensors and eager execution · Essentials · 8 min

    tf.Tensor is an immutable, typed n-dimensional array; in TF 2 operations run eagerly and convert to NumPy with .numpy().

  2. Tensor math and broadcasting · Essentials · 10 min

    Element-wise math, matmul, reductions along an axis, broadcasting and explicit dtype casting with tf.cast.

  3. Indexing, gathering and reshaping · Essentials · 10 min

    Slice tensors, select with tf.gather, tf.boolean_mask and tf.where, and change shapes with reshape, expand_dims, concat and stack.

  4. Variables · Essentials · 8 min

    tf.Variable holds mutable state such as weights; update it with assign, assign_add and assign_sub.

  5. Strings, ragged tensors and text · Practical · 12 min

    Process text in TensorFlow with tf.strings, represent variable-length data with RaggedTensor, and vectorise with TextVectorization.

Automatic differentiation

  1. Gradients with GradientTape · Essentials · 12 min

    Record operations inside tf.GradientTape and call tape.gradient to differentiate a loss with respect to variables.

  2. Custom and higher-order gradients · Expert · 14 min

    Override gradients with @tf.custom_gradient, stop them with tf.stop_gradient, and compute Jacobians and Hessians with nested tapes.

Models & training

  1. Building models with tf.keras · Essentials · 12 min

    Define, compile and fit a model with tf.keras, which in TF 2.16+ is Keras 3, TensorFlow's high-level API.

  2. Custom training loops · Practical · 15 min

    Write your own train step with GradientTape and optimizer.apply_gradients, compiled with tf.function.

  3. Training checkpoints · Practical · 10 min

    Save and restore training state with tf.train.Checkpoint and CheckpointManager, or the Keras ModelCheckpoint callback.

  4. TensorBoard · Practical · 10 min

    Log scalars, histograms and graphs with tf.summary or the Keras TensorBoard callback, and compare runs in the TensorBoard UI.

Input pipelines

  1. tf.data input pipelines · Essentials · 12 min

    Build input pipelines with tf.data.Dataset: from_tensor_slices, map, shuffle, batch, and iterate or pass them to fit.

  2. Fast input pipelines · Practical · 12 min

    Keep accelerators busy with parallel map, cache, prefetch and interleave, using tf.data.AUTOTUNE.

Hardware & scaling

  1. Devices and GPUs · Essentials · 8 min

    Check for GPUs, understand automatic placement, pin ops with tf.device, and enable memory growth.

  2. Distribution strategies · Advanced · 15 min

    Train on several GPUs, machines or TPUs with tf.distribute strategies: create variables under strategy.scope() and keep the rest of the code.

  3. Mixed precision · Advanced · 10 min

    Speed up training with float16 or bfloat16 compute via the mixed_float16 / mixed_bfloat16 policy, keeping outputs and variables in float32.

Graphs & tf.function

  1. tf.function and tracing · Practical · 15 min

    Compile Python functions into TensorFlow graphs with @tf.function, and understand tracing, retracing and Python side effects.

  2. XLA compilation · Advanced · 12 min

    Compile functions with XLA via tf.function(jit_compile=True) to fuse operations into fewer, faster kernels.

  3. AutoGraph and graph control flow · Expert · 15 min

    How AutoGraph rewrites Python if/while/for into tf.cond and tf.while_loop, when loops are unrolled instead, and TensorArray for accumulating results.

  4. Concrete functions and graphs · Expert · 14 min

    Polymorphic tf.function versus ConcreteFunction, inspecting the underlying tf.Graph, and how Grappler optimises graphs before execution.

  5. Runtime, kernels and threading · Expert · 14 min

    How ops map to device kernels, the eager and graph executors, intra- and inter-op thread pools, raw ops, and custom C++ ops.

Saving & deployment

  1. SavedModel export · Practical · 12 min

    Export models as SavedModel with concrete signatures for serving, and reload them without the original Python code.

  2. On-device models with LiteRT · Advanced · 12 min

    Convert models to the .tflite format for mobile and edge with the TFLite converter, quantise them, and run them with the interpreter.

  3. Serving with TF Serving · Advanced · 12 min

    Serve SavedModels over REST and gRPC with TensorFlow Serving, using versioned directories for zero-downtime updates.