TF-Keras Nightly
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
- breaking Keras optimizers were moved to `tf.keras.optimizers.legacy` starting with TensorFlow 2.12. Directly instantiating `keras.optimizers.Adam()` (or other optimizers) will use the new Keras 3 optimizers, which handle state differently and may break checkpoint loading from models trained with older optimizers.
- breaking The default Keras model saving format for `model.save()` is now the `.keras` format (Keras V3 format), not the legacy H5 format, when using `model.save('my_model.keras')`. This change was introduced with TensorFlow 2.13 and Keras 2.13.
- gotcha `tf-keras-nightly` is a nightly build, meaning it's built from the latest development branch and is not guaranteed to be stable or backward compatible between daily releases.
- gotcha Requires Python >=3.10. Installing with older Python versions will result in an installation error.
Install
-
pip install tf-keras-nightly
Imports
- keras
from tensorflow import keras
- keras
import tensorflow.keras as keras
Quickstart
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.")