TF-Keras Nightly

2.21.0.dev2026032809 · active · verified Sun Mar 29

TF-Keras is a deep learning API written in Python, running on top of the machine learning platform TensorFlow. It was developed with a focus on enabling fast experimentation and providing a delightful developer experience. As a nightly build, it offers the very latest features and bug fixes, with daily releases. The current version is 2.21.0.dev2026032809.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define, compile, train, and save a basic Keras Sequential model using the `tensorflow.keras` API. It uses dummy data for a simple classification task.

import tensorflow as tf
import os

# Ensure Keras backend is set to TensorFlow if running multi-backend Keras 3
# (though tf-keras-nightly implies TensorFlow backend by nature)
# os.environ["KERAS_BACKEND"] = "tensorflow"

# Import Keras from TensorFlow's namespace
from tensorflow import keras
from keras import layers

# Define a simple sequential model
model = keras.Sequential([
    layers.Dense(64, activation='relu', input_shape=(784,)),
    layers.Dense(64, activation='relu'),
    layers.Dense(10, activation='softmax')
])

# Compile the model
model.compile(
    optimizer=keras.optimizers.Adam(learning_rate=0.001),
    loss=keras.losses.SparseCategoricalCrossentropy(),
    metrics=[keras.metrics.SparseCategoricalAccuracy()]
)

# Generate dummy data
import numpy as np
x_train = np.random.rand(100, 784).astype('float32')
y_train = np.random.randint(0, 10, 100).astype('int32')

# Train the model
print("Starting model training...")
model.fit(x_train, y_train, epochs=1, batch_size=32)
print("Model training finished.")

# Save the model (using the recommended .keras format)
model.save('my_model.keras')
print("Model saved as my_model.keras")

# Load the model
loaded_model = keras.models.load_model('my_model.keras')
print("Model loaded successfully.")

view raw JSON →