Uses keras.ops and built-in layers
AI Models & Assistants / Knowledge library
Keras
high-level neural networks with multiple backends
Why learn Keras?
Reduces boilerplate when building neural networks while allowing lower-level customization. Backend portability depends on the operations and components used.
Where it came from
Keras provides layers, models, training loops, and serialization for deep learning. Keras 3 supports multiple execution backends, including TensorFlow, JAX, and PyTorch.
Build your understanding
Work through these exercises in order. Try the task before opening a reference.
- Build a small Sequential classifier.
- Inspect tensor shapes through each layer.
- Add validation and early stopping.
- Save and reload a model and compare predictions.
- Test supported operations before switching backends.
Documentation and sources
- Official documentation (keras.io)
Catalog research notes
- Research snapshot: September 9, 2026. This entry summarizes the linked primary documentation; it does not assert a latest release version.
Connect the ideas
Built on
Explore next
Real World Example
Cross-Framework Model Portability for Retail Analytics
Retail enterprises managing diverse machine learning infrastructure across different cloud and on-premise environments.
The business problem
Teams are siloed by framework choice, leading to redundant development of identical model architectures for PyTorch-based research and TensorFlow-based production environments, increasing technical debt and maintenance costs.
How this topic solves it
Keras 3 enables developers to write a single model definition using backend-agnostic APIs, allowing the same codebase to run seamlessly on JAX, TensorFlow, or PyTorch backends without modification.
- Define the model architecture using only built-in Keras layers or the keras.ops namespace.
- Configure the environment variable KERAS_BACKEND to target the desired framework (e.g., 'torch', 'tensorflow', or 'jax').
- Utilize the standard Keras fit() or predict() routines which accept data from any source, including PyTorch DataLoaders or tf.data.Dataset.
- Save the model in the framework-agnostic .keras format for deployment across different backend environments.
Shows how a single Keras definition targets multiple backends.
High-performance training
Research integration
Production serving
Unified model artifacts
- Keras Model Code → compiles to → JAX Backend
- Keras Model Code → compiles to → PyTorch Backend
- Keras Model Code → compiles to → TensorFlow Backend
- JAX Backend → exports → Deployment
- PyTorch Backend → exports → Deployment
- TensorFlow Backend → exports → Deployment
Implementation example
Demonstrates setting the backend environment variable to PyTorch and using standard Keras layers that function regardless of the underlying framework.
import os
os.environ['KERAS_BACKEND'] = 'torch' # Switch backend to PyTorch
import keras
from keras import layers
# Define model once using backend-agnostic layers
model = keras.Sequential([layers.Dense(64, activation='relu'), layers.Dense(10)])
# Compile and train using standard Keras API
model.compile(optimizer='adam', loss='mse')
# model.fit(data_loader) # Works with PyTorch DataLoaderExpected business outcome
Unified model development lifecycle that eliminates framework-specific code duplication and ensures consistent model logic across heterogeneous deployment environments.
Limitations and checks
While logic is portable, random number generator behavior and floating-point implementations differ across backends, which can lead to minor numerical divergence over long training runs. Verify consistency by comparing output precision across backends.