Learn Keras

High-level deep learning API that runs on JAX, TensorFlow or PyTorch

21 lessons · 4 hours · 4 levels · covers Keras 3.x

Keras is a high-level API for building and training neural networks with layers, models, fit() and callbacks. Keras 3 is multi-backend: the same model code runs on JAX, TensorFlow or PyTorch, chosen with one setting. It is the fastest way to go from idea to trained model, and it scales to custom training steps and distributed training when you need them.

Before you start

Keras 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 basics6 lessons · 1 hour in total
2. PracticalUse it productively at work, with the usual idioms13 lessons · 2 hours in total
3. AdvancedThe less common features, performance and trade-offs18 lessons · 3 hours in total
4. ExpertInternals and the edge cases experts know21 lessons · 4 hours in total

The Keras tree

KerasKeras 3 and its backendsKeras 3 and itsbackendsThe Sequential modelThe Sequential modelCore layersCore layerscompile, fit, evaluate, predictcompile, fit, evaluate,predictThe functional APIThe functional APILosses, optimizers and metricsLosses, optimizersand metricsFeeding data to fit()Feeding data to fit()CallbacksCallbacksRegularization and augmentationRegularization andaugmentationPreprocessing layersPreprocessing layersSaving and exporting modelsSaving and exportingmodelsSubclassing keras.ModelSubclassingkeras.Modelkeras.ops: backend-agnostic mathkeras.ops:backend-agnostic…Modules and importsModules and importsClasses and instancesClasses andinstancesVectorized arithmeticVectorized arithmetic
Essentials and Practical shown (13 of 21 lessons); the full list is below. Click a lesson to read it.

All 21 lessons, in order

Getting started

  1. Keras 3 and its backends · Essentials · 7 min

    Keras 3 runs the same code on JAX, TensorFlow or PyTorch; pick the backend with KERAS_BACKEND before importing keras.

Models

  1. The Sequential model · Essentials · 8 min

    Stack layers in keras.Sequential, declare the input shape with keras.Input, and inspect the model with summary().

  2. The functional API · Essentials · 12 min

    Build models as graphs of layers: multiple inputs and outputs, skip connections and shared layers, with keras.Model(inputs, outputs).

  3. Subclassing keras.Model · Practical · 12 min

    Write models as Python classes: create layers in __init__ and define the forward pass in call(), with a training flag.

Layers & preprocessing

  1. Core layers · Essentials · 10 min

    Dense, Conv2D, pooling, Flatten, Embedding, recurrent and normalization layers: what they do and how they change shapes.

  2. Regularization and augmentation · Practical · 12 min

    Fight overfitting with Dropout, weight regularizers, BatchNormalization and augmentation layers that only act during training.

  3. Preprocessing layers · Practical · 12 min

    Normalize numeric features, encode categories and text with Normalization, StringLookup, IntegerLookup and TextVectorization, learning their state with adapt().

  4. keras.ops: backend-agnostic math · Practical · 10 min

    Write numerical code once with keras.ops (a NumPy-like API plus neural-net ops) and keras.random, and run it on any backend.

  5. Writing custom layers · Advanced · 14 min

    Subclass keras.layers.Layer with build() and add_weight(), implement call() with keras.ops, and make it serializable with get_config().

Training

  1. compile, fit, evaluate, predict · Essentials · 12 min

    Configure training with compile(optimizer, loss, metrics), train with fit(), measure with evaluate() and run inference with predict().

  2. Losses, optimizers and metrics · Essentials · 12 min

    Choose the right loss for your labels, configure optimizers and learning-rate schedules, and understand stateful metrics.

  3. Feeding data to fit() · Practical · 12 min

    Train from NumPy arrays, tf.data datasets, PyTorch DataLoaders or a keras.utils.PyDataset, with any backend.

  4. Callbacks · Practical · 10 min

    Hook into fit() with EarlyStopping, ModelCheckpoint, ReduceLROnPlateau, TensorBoard and your own Callback subclasses.

  5. Saving and exporting models · Practical · 10 min

    Save full models in the .keras format, save or load weights only, and export inference artifacts for serving.

  6. Custom losses and metrics · Advanced · 12 min

    Write losses as functions or Loss subclasses, and stateful metrics as Metric subclasses with add_variable, update_state and result.

Advanced workflows

  1. Customizing what fit() does · Advanced · 15 min

    Override train_step in a keras.Model subclass to control each training step while keeping fit(), callbacks and metrics.

  2. Transfer learning and fine-tuning · Advanced · 14 min

    Reuse pretrained keras.applications or KerasHub models: freeze the base, train a new head, then fine-tune with a low learning rate.

  3. Mixed precision · Advanced · 10 min

    Train faster with the mixed_bfloat16 or mixed_float16 dtype policy, keeping variables and outputs in float32.

Internals & scaling

  1. Stateless training with JAX · Expert · 18 min

    How Keras runs on JAX: stateless_call and stateless_apply pass variable values explicitly, enabling jax.jit and jax.grad over Keras models.

  2. The keras.distribution API · Expert · 16 min

    Shard data and model weights across devices with DeviceMesh, LayoutMap, DataParallel and ModelParallel (JAX backend).

  3. Serialization and layer internals · Expert · 14 min

    What a .keras file contains, how get_config/from_config rebuild objects, safe_mode, and how Keras tracks variables in layers.