Skip to content
AIRepoHub

keras

by keras-team

Beginner-friendly deep learning library for building and training neural networks in Python.

Developer ToolsPythonApache 2.0 license
Stars
64,450
stars
Forks
20k
forks
Last push
today
Activity
Active
keras: quick start
# 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

Based on official documentation

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. 1

    Install Keras

    Shell
    pip install keras --upgrade
  2. 2

    Install a backend

    tensorflow, jax or torch.

    Shell
    pip install jax
  3. 3

    Select the backend

    Or edit ~/.keras/keras.json.

    Shell
    export KERAS_BACKEND="jax"

Configuration and API keys

SettingWhat it's for
KERAS_BACKENDOptionaltensorflow, jax, torch or openvino; set before importing keras.

First run

  1. 1

    Check Keras imports with your backend

    Shell
    python -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. 1

    Get the example

    examples/demo_mnist_convnet.py in the Keras repository.

  2. 2

    Run it

    It loads MNIST, trains a two-layer convnet for 3 epochs and evaluates it.

    Shell
    python 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.

Source: README.md

CUDA version conflicts

Use a separate clean environment per backend with its requirements-{backend}-cuda.txt.

Source: README.md

Running on Windows

Use WSL2, as the README recommends.

Source: README.md

Alternatives

Similar AI repositories