keras
by keras-team
Beginner-friendly deep learning library for building and training neural networks in Python.
- Stars
- 64,450 stars
- Forks
- 20k forks
- Last push
- today
- Activity
- Active
# Install Keras 3$ pip install keras --upgrade# Install a backend, for example JAX$ pip install jax# Choose the backend$ export KERAS_BACKEND="jax"Commands from the project's README. Run them after installing (see below).
Overview
Understand keras in 60 seconds
- What it does
- Keras 3 is a high-level deep learning framework that runs on top of JAX, TensorFlow or PyTorch (and OpenVINO for inference). You build and train models for vision, language, audio, time series and recommendations with the same simple API, whichever backend you choose.
- The problem it solves
- Deep learning code is usually tied to one framework. Keras lets you write models once and run them on the backend that is fastest or best supported for your project, and the README cites speedups of 20% to 350% depending on the backend.
- Why choose it
- Choose it for a friendly, well-documented API that avoids framework lock-in. It's officially supported on Linux and macOS; on Windows the README recommends WSL2.
- Who should use it
- Beginners learning deep learning
- Researchers who want backend flexibility
- Teams moving from tf.keras
- PyTorch or JAX users who want a high-level training API
- Setup difficulty
You'll need:
- Python
- One backend: TensorFlow 2.16.1+, JAX 0.4.20+ or PyTorch 2.6.0+
- Linux or macOS (WSL2 on Windows)
How keras works
Keras 3 is published on PyPI as keras; Keras 2 remains available as tf-keras. After installing keras you install a backend package and select it with the KERAS_BACKEND environment variable or ~/.keras/keras.json. The backend must be set before importing keras.
It is intended as a drop-in replacement for tf.keras with the TensorFlow backend; models without custom components can run on JAX or PyTorch immediately. Keras models can train on tf.data pipelines or PyTorch DataLoaders, and can be used inside native PyTorch modules or JAX functions.
For GPU support, the repository provides requirements files per backend that install CUDA dependencies through pip, and recommends a clean environment per backend. The OpenVINO backend only supports model.predict().
Features
Key features
Multi-backend
JAX, TensorFlow, PyTorch and OpenVINO (inference).
High-level API
Sequential and functional models, layers, fit and evaluate.
tf.keras compatible
Drop-in replacement with the TensorFlow backend.
Mix with native code
Use Keras models in PyTorch or JAX workflows.
Any data pipeline
tf.data or PyTorch DataLoaders.
Scales up
From laptop to GPU and TPU clusters.
Strengths
- Beginner-friendly API
- Avoids framework lock-in
- Excellent documentation at keras.io
- Apache-2.0 licensed
Limitations
- Windows needs WSL2
- Backend must be chosen before import
- OpenVINO backend is inference-only
Practical use cases
Image classification
Train a convolutional network on MNIST.
Port tf.keras code
Run existing models on JAX or PyTorch.
Research prototypes
Switch backends to compare speed.
Installation
Install keras
Commands come from Keras's README. AIRepoHub hasn't run them yet. View source
Prerequisites
- Python
- A backend package
Supported systems
- Linux
- macOS
- Windows (WSL2)
- 1
Install Keras
Shellpip install keras --upgrade - 2
Install a backend
tensorflow, jax or torch.
Shellpip install jax - 3
Select the backend
Or edit ~/.keras/keras.json.
Shellexport KERAS_BACKEND="jax"
- 1
Clone the repository
Shellgit clone https://github.com/keras-team/keras.gitcd keras - 2
Create a clean environment and install
Run inside a clone of the Keras repository. Expects an NVIDIA driver to be installed.
Shellconda create -y -n keras-jax python=3.10conda activate keras-jaxpip install -r requirements-jax-cuda.txtpython pip_build.py --install
Configuration and API keys
| Setting | What it's for |
|---|---|
KERAS_BACKENDOptional | tensorflow, jax, torch or openvino; set before importing keras. |
First run
- 1
Check Keras imports with your backend
Shellpython -c "import keras; print(keras.backend.backend())"
keras's documentation doesn't include sample output, so we don't show any. Expect the results in your terminal.
Your first project
Train a digit classifier on MNIST
Build and train a small convolutional network with the repository's example.
Before you start
- Keras and a backend installed
- KERAS_BACKEND set
- 1
Get the example
examples/demo_mnist_convnet.py in the Keras repository.
- 2
Run it
It loads MNIST, trains a two-layer convnet for 3 epochs and evaluates it.
Shellpython examples/demo_mnist_convnet.py
What to expect
The script prints the model summary, training progress, and the test loss and accuracy.
Next steps
- Switch KERAS_BACKEND and run it again
- Read the guides at keras.io
- Try the functional API example
Costs and requirements
What it costs to run
- License
- Apache-2.0.Free
- Software
- Free and open source.Free
- Compute
- Your CPU or GPU, or cloud accelerators.Depends
Troubleshooting
Common setup issues
Backend didn't change
Set KERAS_BACKEND before importing keras; it can't change after import.
CUDA version conflicts
Use a separate clean environment per backend with its requirements-{backend}-cuda.txt.
Running on Windows
Use WSL2, as the README recommends.
Alternatives
Similar AI repositories
markitdown
microsoft
Python tool from Microsoft that converts PDFs, Word, Excel, PowerPoint and other files into Markdown for use with AI.
transformers
huggingface
Hugging Face library for defining, running and training machine learning models for text, vision and audio.
langchain
langchain-ai
Framework for building LLM-powered applications and agents.
pytorch
pytorch
Python framework for building and training neural networks with tensors and GPU acceleration.