{"id":7339,"library":"keras-nightly","title":"Keras Nightly","description":"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.","status":"active","version":"3.15.0.dev2026041504","language":"en","source_language":"en","source_url":"https://github.com/keras-team/keras","tags":["deep learning","machine learning","neural networks","nightly","multi-backend"],"install":[{"cmd":"pip install keras-nightly","lang":"bash","label":"Install Keras Nightly"},{"cmd":"pip install tensorflow","lang":"bash","label":"Install TensorFlow backend (example)"},{"cmd":"pip install jax[cuda12_pip] -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html","lang":"bash","label":"Install JAX backend (example for CUDA 12)"},{"cmd":"pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121","lang":"bash","label":"Install PyTorch backend (example for CUDA 12.1)"}],"dependencies":[{"reason":"Keras 3.x requires Python 3.11 or higher.","package":"python","optional":false},{"reason":"One of the supported deep learning backends for Keras 3.","package":"tensorflow","optional":true},{"reason":"One of the supported deep learning backends for Keras 3.","package":"jax","optional":true},{"reason":"One of the supported deep learning backends for Keras 3.","package":"torch","optional":true},{"reason":"An inference-only backend supported by Keras 3.","package":"openvino","optional":true}],"imports":[{"note":"Keras 3.x is a standalone library. Direct import is 'import keras'. The `tensorflow.keras` namespace refers to Keras 2.x bundled with TensorFlow versions prior to 2.16.","wrong":"from tensorflow import keras","symbol":"keras","correct":"import keras"},{"note":"For Keras 3, all components are imported directly from the `keras` namespace.","wrong":"from tensorflow.keras import layers","symbol":"layers","correct":"from keras import layers"}],"quickstart":{"code":"import os\nimport keras\nimport numpy as np\n\n# Configure the Keras backend (e.g., 'tensorflow', 'jax', 'torch')\nos.environ[\"KERAS_BACKEND\"] = \"tensorflow\" \n\n# Load a dataset\n(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()\nx_train = x_train.astype(\"float32\") / 255\nx_test = x_test.astype(\"float32\") / 255\nx_train = np.expand_dims(x_train, -1)\nx_test = np.expand_dims(x_test, -1)\n\n# Build a simple model\nmodel = keras.Sequential(\n    [\n        keras.layers.Input(shape=(28, 28, 1)),\n        keras.layers.Conv2D(32, kernel_size=(3, 3), activation=\"relu\"),\n        keras.layers.MaxPooling2D(pool_size=(2, 2)),\n        keras.layers.Conv2D(64, kernel_size=(3, 3), activation=\"relu\"),\n        keras.layers.MaxPooling2D(pool_size=(2, 2)),\n        keras.layers.Flatten(),\n        keras.layers.Dropout(0.5),\n        keras.layers.Dense(10, activation=\"softmax\"),\n    ]\n)\n\n# Compile the model\nmodel.compile(optimizer=\"adam\", loss=\"sparse_categorical_crossentropy\", metrics=[\"accuracy\"])\n\n# Train the model\nmodel.fit(x_train, y_train, batch_size=128, epochs=5, validation_split=0.1)\n\n# Evaluate the model\nloss, accuracy = model.evaluate(x_test, y_test)\nprint(f\"Test accuracy: {accuracy:.4f}\")","lang":"python","description":"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`."},"warnings":[{"fix":"Upgrade your Python environment to 3.11 or newer.","message":"Keras 3.13.0 and newer versions require Python 3.11 or higher. Using older Python versions will result in installation or runtime errors.","severity":"breaking","affected_versions":">=3.13.0"},{"fix":"Update all `from tensorflow.keras import ...` statements to `from keras import ...` and `tf.keras.` prefixes to `keras.`.","message":"The `tensorflow.keras` namespace is deprecated for Keras 3.x. All imports should be directly from `keras` (e.g., `import keras`, `from keras import layers`).","severity":"breaking","affected_versions":"Keras 3.x"},{"fix":"For saving, use the native Keras format (`.keras` extension) with `model.save()`. For SavedModel export, use `model.export(filepath)`. For loading existing TensorFlow SavedModels for inference in Keras 3, use `keras.layers.TFSMLayer(saved_model_path, call_endpoint='serving_default')`.","message":"Saving models to the TensorFlow SavedModel format via `model.save()` is no longer supported in Keras 3. Loading TensorFlow SavedModels via `keras.models.load_model()` is also not supported.","severity":"breaking","affected_versions":"Keras 3.x"},{"fix":"For stable production applications, use the `keras` package (stable release) instead of `keras-nightly`.","message":"Keras-nightly builds are development versions and may contain bugs, incomplete features, or unstable APIs. They are not recommended for production environments.","severity":"gotcha","affected_versions":"All nightly builds"},{"fix":"Set the `KERAS_BACKEND` environment variable (e.g., `os.environ[\"KERAS_BACKEND\"] = \"tensorflow\"`) or edit the `~/.keras/keras.json` config file before importing `keras`.","message":"The Keras backend (TensorFlow, JAX, or PyTorch) must be configured *before* the first `import keras` statement in your application. Changing the backend after import is not supported.","severity":"gotcha","affected_versions":"Keras 3.x"},{"fix":"If you encounter XLA errors with custom components, set `jit_compile=False` in your `Model` constructor: `model = keras.Model(..., jit_compile=False)`.","message":"When using the TensorFlow backend with Keras 3 on GPU, `jit_compile` for `Model` is `True` by default. This can cause XLA-related errors if your custom layers or models use TensorFlow operations not supported by XLA.","severity":"gotcha","affected_versions":"Keras 3.x with TensorFlow backend on GPU"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure that your TensorFlow and Keras installations are compatible. Upgrade TensorFlow to a recent version (e.g., 2.16.1+ for Keras 3). It is recommended to install Keras first, then its chosen backend.","cause":"Version incompatibility between TensorFlow and Keras. This error often occurs when an older TensorFlow version is installed with a newer Keras, or vice-versa, that expects a specific internal structure.","error":"ImportError: cannot import name 'type_spec_registry' from 'tensorflow.python.framework'"},{"fix":"Replace `from tensorflow.keras import ...` with `from keras import ...` and `tf.keras.` prefixes with `keras.`.","cause":"Attempting to import Keras components from the `tensorflow.keras` namespace with Keras 3.x installed, which uses the standalone `keras` package.","error":"Import \"tensorflow.keras\" could not be resolved"},{"fix":"When using `model.save()`, use `.keras` (recommended) or `.h5` extensions. If you specifically need to export to the TensorFlow SavedModel format, use `model.export(filepath)` instead.","cause":"Attempting to save a Keras 3 model using `model.save()` with an unsupported file extension (e.g., no extension or `.tf`).","error":"ValueError: Invalid filepath extension for saving. Please add either a `.keras` extension for the native Keras format (recommended) or a `.h5` extension. Use `model.export(filepath)` if you want to export a SavedModel for use with TFLite/TFServing/etc."},{"fix":"Replace native TensorFlow operations (`tf.*`) with their equivalent functions from `keras.ops` (e.g., `keras.ops.matmul` instead of `tf.linalg.matmul`).","cause":"Mixing Keras symbolic tensors (KerasTensors) directly with native TensorFlow operations outside of the `keras.ops` namespace in functional models.","error":"ValueError: A KerasTensor cannot be used as input to a TensorFlow function. A KerasTensor is a symbolic placeholder for a shape and dtype, used when constructing Keras Functional models or Keras Functions. You can only use it as input to a Keras layer or a Keras operation (from the namespaces `keras.layers` and `keras.operations`)."},{"fix":"Ensure consistency in your Keras imports. If using Keras 3, all layers and models should come from the `keras` namespace. Avoid mixing `tf.keras` and `keras` objects. Consider using virtual environments to isolate dependencies.","cause":"This typically occurs in environments where both Keras 3 (standalone) and TensorFlow's bundled Keras 2 (`tf.keras`) are present, leading to a type mismatch when trying to add a layer instantiated from one Keras version into a model from another.","error":"ValueError: Only instances of `keras.Layer` can be added to a Sequential model. Received: <tensorflow_hub.keras_layer.KerasLayer object ...>"}]}