Keras Nightly

3.15.0.dev2026041504 · active · verified Thu Apr 16

Keras 3 is a multi-backend deep learning framework that supports JAX, TensorFlow, PyTorch, and OpenVINO (for inference-only). The `keras-nightly` package provides daily development builds of Keras, offering access to the latest features and bug fixes. It focuses on accelerated model development and state-of-the-art performance by leveraging backend-specific optimizations.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set a Keras backend, load data, build a sequential convolutional neural network, compile it, and train it using Keras 3. Ensure a backend (e.g., TensorFlow) is installed and the `KERAS_BACKEND` environment variable is set before importing `keras`.

import os
import keras
import numpy as np

# Configure the Keras backend (e.g., 'tensorflow', 'jax', 'torch')
os.environ["KERAS_BACKEND"] = "tensorflow" 

# Load a dataset
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
x_train = x_train.astype("float32") / 255
x_test = x_test.astype("float32") / 255
x_train = np.expand_dims(x_train, -1)
x_test = np.expand_dims(x_test, -1)

# Build a simple model
model = keras.Sequential(
    [
        keras.layers.Input(shape=(28, 28, 1)),
        keras.layers.Conv2D(32, kernel_size=(3, 3), activation="relu"),
        keras.layers.MaxPooling2D(pool_size=(2, 2)),
        keras.layers.Conv2D(64, kernel_size=(3, 3), activation="relu"),
        keras.layers.MaxPooling2D(pool_size=(2, 2)),
        keras.layers.Flatten(),
        keras.layers.Dropout(0.5),
        keras.layers.Dense(10, activation="softmax"),
    ]
)

# Compile the model
model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])

# Train the model
model.fit(x_train, y_train, batch_size=128, epochs=5, validation_split=0.1)

# Evaluate the model
loss, accuracy = model.evaluate(x_test, y_test)
print(f"Test accuracy: {accuracy:.4f}")

view raw JSON →