Keras is a high-level deep learning API written in Python that lets developers define, train, evaluate and export neural networks with a small set of consistent building blocks. Among AI frameworks & tools, it occupies the layer above numerical engines: since Keras 3, the same model code runs on JAX, TensorFlow or PyTorch as interchangeable backends.
Keras was created by François Chollet and first released in 2015. It became the official high-level interface of TensorFlow 2 as tf.keras, and the multi-backend Keras 3 release in late 2023 turned it back into an independent, framework-agnostic library. Its design goal is progressive disclosure of complexity: simple models need a few lines, while advanced users can override every step of training.
How Keras structures a deep learning model
Keras structures every model as a graph of layers, which are objects that hold trainable weights and a forward computation. A Model groups layers, tracks their variables and exposes the standard workflow of compile(), fit(), evaluate() and predict().
The compile() step binds three components to the model: an optimizer such as Adam or SGD, a loss function that measures error, and a list of metrics for monitoring. The fit() loop then iterates over batches, computes gradients through the active backend and updates the weights, while callbacks handle checkpoints, early stopping and learning-rate schedules.
Keras offers three ways to build models, and the choice decides how much flexibility and introspection the developer gets. The table below compares them.
| Style | How the model is defined | Best suited for |
|---|---|---|
| Sequential API | A linear stack of layers | Simple feed-forward networks and prototypes |
| Functional API | A directed acyclic graph of layer calls | Multiple inputs, outputs, skip connections |
| Model subclassing | Python class with a custom call() method | Dynamic control flow and research code |
The Functional API is the recommended default for production because the resulting graph can be plotted, serialized and inspected layer by layer. Subclassed models trade that transparency for full Python freedom inside the forward pass.
The multi-backend architecture of Keras 3
Keras 3 separates the user-facing API from the numerical backend that executes tensor operations and computes gradients. The backend is selected with the KERAS_BACKEND environment variable or a configuration file before Keras is imported, and it cannot be switched inside a running process.
The keras.ops namespace provides a NumPy-like operation set that maps to each backend. Custom layers written only with keras.ops stay portable across backends, whereas code that calls torch or tf functions directly ties the model to one engine.
| Backend | Main strength | Typical consideration |
|---|---|---|
| JAX | XLA compilation, fast training on TPUs and GPUs | Functional style requires stateless thinking |
| TensorFlow | Mature serving with SavedModel and TF Serving | Larger install and slower eager debugging |
| PyTorch | Interoperability with the PyTorch ecosystem | Compilation gains depend on torch.compile |
| OpenVINO | Optimized inference on Intel hardware | Inference only, no training support |
Because weights are stored independently of the backend, a model trained with JAX can be reloaded and served with TensorFlow or embedded in a PyTorch pipeline. This portability is the central technical argument for Keras 3.
Keras compared with neighboring frameworks
Keras differs from PyTorch, TensorFlow and JAX mainly in level of abstraction: it is an API that sits on top of them rather than a competing tensor engine. The comparison below reflects how practitioners usually position these tools.
| Tool | Abstraction level | Training loop | Primary audience |
|---|---|---|---|
| Keras | High-level API | Built-in fit(), overridable | Applied engineers and educators |
| PyTorch | Low-level tensor library | Written by the user | Researchers and model developers |
| TensorFlow | Full platform with graph runtime | Usually through Keras | Production and mobile teams |
| JAX | Composable function transforms | Written by the user or Flax | Large-scale research |
| PyTorch Lightning | Training wrapper | Structured Trainer loop | PyTorch users who want less boilerplate |
The closest conceptual neighbor is PyTorch Lightning, which also removes boilerplate, but it remains tied to PyTorch. Keras is unique in offering a single model definition that several engines can execute.
Practical use and configuration of Keras
Keras is used most often for computer vision, text classification, time series forecasting and tabular deep learning, and the KerasHub library supplies pretrained models such as image classifiers and language models with matching preprocessing. Training data can come from tf.data pipelines, PyTorch DataLoader objects, NumPy arrays or Python generators.
Several configuration choices have a large effect on speed and memory. The decision table summarizes common situations.
| Situation | Recommended choice | Reason |
|---|---|---|
| Training on TPUs | JAX backend | Best XLA support and scaling |
| Limited GPU memory | Mixed precision mixed_float16 | Halves activation memory on modern GPUs |
| Model must join a PyTorch codebase | PyTorch backend | Layers behave as torch.nn.Module objects |
| Long training runs | ModelCheckpoint and EarlyStopping callbacks | Protects progress and limits overfitting |
| Multi-device training | keras.distribution API | Data and model parallelism without rewrites |
Models are saved in the native `.keras` format, a zip archive containing the architecture configuration and weights. For deployment, Keras can export inference artifacts such as a TensorFlow SavedModel, which then feeds serving systems or conversion to ONNX or LiteRT.
Limitations and common mistakes with Keras
The convenience of Keras hides details that matter at scale, and most problems arise when backend-specific code leaks into supposedly portable models. Experienced users watch for the following issues.
- Version confusion between
tf.kerasfrom Keras 2 and standalone Keras 3 breaks imports and saved models. - Legacy HDF5 files from older releases may need conversion before loading in Keras 3.
- Custom layers without a
get_config()method fail to deserialize from the.kerasformat. - Calling backend functions directly inside layers removes portability to other backends.
- Very unusual research loops can feel constrained, although overriding
train_step()usually solves this.
Performance also varies by backend and model type, so benchmarking each backend on the actual workload is more reliable than assuming one engine is always fastest.
The short version
Keras is a toolkit that makes building neural networks feel like assembling building blocks. A developer picks layers, stacks or connects them, and tells Keras how to learn from data. Keras then handles the heavy mathematics in the background.
The newest version adds one useful trick: it can run on three different engines, JAX, TensorFlow or PyTorch, without rewriting the model. It is like writing a document once and printing it on any brand of printer. The key takeaway is that Keras trades a little low-level control for speed and simplicity.
Where it makes a difference
A small machine learning team at a regional logistics company needs a model that reads photos of damaged parcels and sorts them into four damage categories. Using KerasHub, an engineer loads a pretrained image classifier, replaces the final layer with a four-class output, and fine-tunes it on about 12,000 labeled photos with the JAX backend on a single cloud GPU.
Training with mixed precision and an EarlyStopping callback finishes in under two hours and reaches about 93 percent validation accuracy. The company’s existing serving stack runs on TensorFlow, so the team reloads the same .keras file with the TensorFlow backend and exports a SavedModel. The result is a model trained on one engine and served on another with no code rewrite, which shortened the project by several weeks.