keras.ioAI tool

keras-io

keras.io
Pricing plans

Detailed pricing plans are not available yet for this tool.

Detailed overview
KERAS 3.0 RELEASED A superpower for ML developers Keras is a deep learning API designed for human beings, not machines. Keras focuses on debugging speed, code elegance & conciseness, maintainability, and deployability. When you choose Keras, your codebase is smaller, more readable, easier to iterate on. API DOCS GUIDES EXAMPLES Copied inputs = keras.Input(shape=(32, 32, 3)) x = layers.Conv2D(32, 3, activation="relu")(inputs) x = layers.Conv2D(64, 3, activation="relu")(x) residual = x = layers.MaxPooling2D(3)(x) x = layers.Conv2D(64, 3, padding="same")(x) x = layers.Activation("relu")(x) x = layers.Conv2D(64, 3, padding="same")(x) x = layers.Activation("relu")(x) x = x + residual x = layers.Conv2D(64, 3, activation="relu")(x) x = layers.GlobalAveragePooling2D()(x) outputs = layers.Dense(10, activation="softmax")(x) model = keras.Model(inputs, outputs, name="mini_resnet") keras.utils.plot_model(model, "mini_resnet.png") model.fit(dataset, epochs=10) Run quickstart Copied causal_lm = keras_hub.models.CausalLM.from_preset( "gemma2_instruct_2b_en", dtype="float16", ) prompt = """user Write python code to print the first 100 primes. model """ text_output = causal_lm.generate(prompt, max_length=512) text_to_image = keras_hub.models.TextToImage.from_preset( "stable_diffusion_3_medium", dtype="float16", ) prompt = "Astronaut in a jungle, detailed" image_output = text_to_image.generate(prompt) Run quickstart Welcome to multi-framework machine learning With its multi-backend approach, Keras gives you the freedom to work with JAX, TensorFlow, and PyTorch. Build models that can move seamlessly across these frameworks and leverage the strengths of each ecosystem. GET STARTED Developer Guides VIEW ALL Copied inputs = keras.Input(shape=(28, 28, 1)) x = inputs x = layers.Conv2D(16, 3, activation="relu")(x) x = layers.Conv2D(32, 3, activation="relu")(x) x = layers.MaxPooling2D(3)(x) x = layers.Conv2D(32, 3, activation="relu")(x) x = layers.Conv2D(16, 3, activation="relu")(x) x = layers.GlobalMaxPooling2D()(x) x = layers.Dropout(0.5) outputs = layers.Dense(10) model = keras.Model(inputs, outputs) model.summary() The Functional API Starting from the beginning and learn how to build models using the functional building pattern. VIEW GUIDE Copied model.compile( optimizer="rmsprop", loss="categorical_crossentropy", metrics=["accuracy"], ) history = model.fit( x_train, y_train, batch_size=64, epochs=2, validation_data=(x_val, y_val), ) Training & evaluation with the built-in methods Train and evaluate your model using model.fit(...). VIEW GUIDE Copied class MLPBlock(keras.layers.Layer): def __init__(self): super().__init__() self.dense_1 = layers.Dense(32) self.dense_2 = layers.Dense(32) self.dense_3 = layers.Dense(1) def call(self, inputs): x = self.dense_1(inputs) x = keras.activations.relu(x) x = self.dense_2(x) x = keras.activations.relu(x) return self.dense_3(x) Making new layers and models via subclassing Learn how to customize your model via subclassing Keras layers. VIEW GUIDE VIEW ALL KerasHub The KerasHub library provides Keras 3 implementations of popular model architectures, paired with a collection of pretrained checkpoints available on Kaggle Models. Models can be used for both training and inference, on any of the TensorFlow, JAX, and PyTorch backends. SEE ALL GEMMA Google’s family of lightweight language models built from the same research and technology used to create Gemini. VIEW DOCUMENTATION KAGGLE DETAILS LLAMA Meta’s flagship open text generation models available in a wide range of sizes and precisions. VIEW DOCUMENTATION KAGGLE DETAILS STABLE DIFFUSION Generate image content with this state of the art diffusion model from Stability AI. VIEW DOCUMENTATION KAGGLE DETAILS MISTRAL A generative language from the French company Mistral AI, making frontier models accessible to all. VIEW DOCUMENTATION KAGGLE DETAILS SEE ALL Code examples VIEW ALL Computer vision Take a look at our examples for doing image classification, object detection, video processing, and more. SEE EXAMPLE Natural Language Processing We also have many guides for doing NLP including text classification, machine translation, and language modeling. SEE EXAMPLE Generative Deep Learning Get started with generative deep learning with our wealth of guides involving state-of-the-art diffusion models, GANs, and transformer models. SEE EXAMPLE VIEW ALL Trusted for research and production Keras is used by CERN, NASA, NIH, and many more scientific organizations around the world (and yes, Keras is used at the Large Hadron Collider). Keras is used by Waymo to power self-driving vehicles. Keras partners with Kaggle and HuggingFace to meet ML developers in the tools they use daily. Stay in touch Sign up to our mailing list for regular updates and discussions about the Keras ecosystem. Listen in at our community meetings, and follow us on social media! JOIN GOOGLE GROUP JOIN COMMUNITY MEETING DISCORD GOOGLE AI FORUM Contributions welcome! We welcome your code, ideas, and feedback as we continue to grow. Visit our roadmap, contribution guide or GitHub for more information. VIEW ROADMAP CONTRIBUTION GUIDE GITHUB --- None Getting started About Keras Introduction to Keras for engineers Keras 3 benchmarks The Keras ecosystem Frequently Asked Questions ► Getting started with Keras Getting started with Keras Learning resources Are you a machine learning engineer looking for a Keras introduction one-pager? Read our guide Introduction to Keras for engineers. Want to learn more about Keras 3 and its capabilities? See the Keras 3 launch announcement. Are you looking for detailed guides covering in-depth usage of different parts of the Keras API? Read our Keras developer guides. Are you looking for tutorials showing Keras in action across a wide range of use cases? See the Keras code examples: over 150 well-explained notebooks demonstrating Keras best practices in computer vision, natural language processing, and generative AI. Installing Keras 3 You can install Keras from PyPI via: Copied!pip install --upgrade keras You can check your local Keras version number via: Copied!import keras print(keras.__version__) To use Keras 3, you will also need to install a backend framework – either JAX, TensorFlow, or PyTorch: Installing JAX Installing TensorFlow Installing PyTorch If you install TensorFlow 2.15, you should reinstall Keras 3 afterwards. The cause is that tensorflow==2.15 will overwrite your Keras installation with keras==2.15. This step is not necessary for TensorFlow versions 2.16 onwards as starting in TensorFlow 2.16, it will install Keras 3 by default. Installing KerasCV and KerasHub KerasCV and KerasHub can be installed via pip: Copied!pip install --upgrade keras-cv pip install --upgrade keras-hub pip install --upgrade keras Configuring your backend You can export the environment variable KERAS_BACKEND or you can edit your local config file at ~/.keras/keras.json to configure your backend. Available backend options are: "jax", "tensorflow", "torch". Example: Copied!export KERAS_BACKEND="jax" In Colab, you can do: Copied!import os os.environ["KERAS_BACKEND"] = "jax" import keras Note: The backend must be configured before importing Keras, and the backend cannot be changed after the package has been imported. GPU dependencies Colab or Kaggle If you are running on Colab or Kaggle, the GPU should already be configured, with the correct CUDA version. Installing a newer version of CUDA on Colab or Kaggle is typically not possible. Even though pip installers exist, they rely on a pre-installed NVIDIA driver and there is no way to update the driver on Colab or Kaggle. Universal GPU environment If you want to attempt to create a "universal environment" where any backend can use the GPU, we recommend following the dependency versions used by Colab (which seeks to solve this exact problem). You can install the CUDA driver from here, then pip install backends by following their respective CUDA installation instructions: Installing JAX, Installing TensorFlow, Installing PyTorch Most stable GPU environment This setup is recommended if you are a Keras contributor and are running Keras tests. It installs all backends but only gives GPU access to one backend at a time, avoiding potentially conflicting dependency requirements between backends. You can use the following backend-specific requirements files: requirements-jax-cuda.txt requirements-tensorflow-cuda.txt requirements-torch-cuda.txt These install all CUDA-enabled dependencies via pip. They expect a NVIDIA driver to be preinstalled. We recommend a clean python environment for each backend to avoid CUDA version mismatches. As an example, here is how to create a JAX GPU environment with Conda: Copied!conda create -y -n keras-jax python=3.11 conda activate keras-jax pip install -r requirements-jax-cuda.txt pip install --upgrade keras TensorFlow + Keras 2 backwards compatibility From TensorFlow 2.0 to TensorFlow 2.15 (included), doing pip install tensorflow will also install the corresponding version of Keras 2 – for instance, pip install tensorflow==2.14.0 will install keras==2.14.0. That version of Keras is then available via both import keras and from tensorflow import keras (the tf.keras namespace). Starting with TensorFlow 2.16, doing pip install tensorflow will install Keras 3. When you have TensorFlow >= 2.16 and Keras 3, then by default from tensorflow import keras (tf.keras) will be Keras 3. Meanwhile, the legacy Keras 2 package is still being released regularly and is available on PyPI as tf_keras (or equivalently tf-keras – note that - and _ are equivalent in PyPI package names). To use it, you can install it via pip install tf_keras then import it via import tf_keras as keras. Should you want tf.keras to stay on Keras 2 after upgrading to TensorFlow 2.16+, you can configure your TensorFlow installation so that tf.keras points to tf_keras. To achieve this: Make sure to install tf_keras. Note that TensorFlow does not install it by default. Export the environment variable TF_USE_LEGACY_KERAS=1. There are several ways to export the environment variable: You can simply run the shell command export TF_USE_LEGACY_KERAS=1 before launching the Python interpreter. You can add export TF_USE_LEGACY_KERAS=1 to your .bashrc file. That way the variable will still be exported when you restart your shell. You can start your Python script with: Copied!import os os.environ["TF_USE_LEGACY_KERAS"] = "1" These lines would need to be before any import tensorflow statement. Compatibility matrix JAX compatibility The following Keras + JAX versions are compatible with each other: jax==0.4.20 & keras~=3.0 TensorFlow compatibility The following Keras + TensorFlow versions are compatible with each other: To use Keras 2: tensorflow~=2.13.0 & keras~=2.13.0 tensorflow~=2.14.0 & keras~=2.14.0 tensorflow~=2.15.0 & keras~=2.15.0 To use Keras 3: tensorflow~=2.16.1 & keras~=3.0 PyTorch compatibility The following Keras + PyTorch versions are compatible with each other: torch~=2.1.0 & keras~=3.0 Getting started with Keras Learning resources Installing Keras 3 Installing KerasCV and KerasHub Configuring your backend GPU dependencies TensorFlow + Keras 2 backwards compatibility Compatibility matrix JAX compatibility TensorFlow compatibility PyTorch compatibility --- None Developer guides The Functional API The Sequential model Making new layers & models via subclassing Training & evaluation with the built-in methods Customizing `fit()` with JAX Customizing `fit()` with TensorFlow Customizing `fit()` with PyTorch Writing a custom training loop in JAX Writing a custom training loop in TensorFlow Writing a custom training loop in PyTorch Serialization & saving Customizing saving & serialization Writing your own callbacks Transfer learning & fine-tuning Distributed training with JAX Distributed training with TensorFlow Distributed training with PyTorch Distributed training with Keras 3 Migrating Keras 2 code to Keras 3 How to use Keras with NNX backend Orbax Checkpointing in Keras Quantization in Keras 8-bit integer quantization in Keras 4-bit integer quantization in Keras GPTQ quantization in Keras Writing quantization-compatible layers in Keras Customizing quantization in Keras Define a Custom TPU/GPU Kernel ► Developer guides Developer guides Our developer guides are deep-dives into specific topics such as layer subclassing, fine-tuning, or model saving. They're one of the best ways to become a Keras expert. Most of our guides are written as Jupyter notebooks and can be run in one click in Google Colab, a hosted notebook environment that requires no setup and runs in the cloud. Google Colab includes GPU and TPU runtimes. Available guides The Functional API The Sequential model Making new layers & models via subclassing Training & evaluation with the built-in methods Customizing fit() with JAX Customizing fit() with TensorFlow Customizing fit() with PyTorch Writing a custom training loop in JAX Writing a custom training loop in TensorFlow Writing a custom training loop in PyTorch Serialization & saving Customizing saving & serialization Writing your own callbacks Transfer learning & fine-tuning Distributed training with JAX Distributed training with TensorFlow Distributed training with PyTorch Distributed training with Keras 3 Migrating Keras 2 code to Keras 3 How to use Keras with NNX backend Orbax Checkpointing in Keras Quantization in Keras 8-bit integer quantization in Keras 4-bit integer quantization in Keras GPTQ quantization in Keras Writing quantization-compatible layers in Keras Customizing quantization in Keras Define a Custom TPU/GPU Kernel Developer guides Available guides