Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

KerasHub: Multi-framework Pretrained Models

Python contributions welcome

KerasHub is a pretrained modeling library that aims to be simple, flexible, and fast. The library provides Keras 3 implementations of popular model architectures, paired with a collection of pretrained checkpoints available on Kaggle Models. Models can be used with text, image, and audio data for generation, classification, and many other built in tasks.

KerasHub is an extension of the core Keras API; KerasHub components are provided as Layer and Model implementations. If you are familiar with Keras, congratulations! You already understand most of KerasHub.

All models support JAX, TensorFlow, and PyTorch from a single model definition and can be fine-tuned on GPUs and TPUs out of the box. Models can be trained on individual accelerators with built-in PEFT techniques, or fine-tuned at scale with model and data parallel training. See our Getting Started guide to start learning our API.

For everyone

For contributors

Quickstart

Choose a backend:

import os
os.environ["KERAS_BACKEND"] = "jax"  # Or "tensorflow" or "torch"!

Import KerasHub and other libraries:

import keras
import keras_hub
import numpy as np
import tensorflow_datasets as tfds

Load a resnet model and use it to predict a label for an image:

classifier = keras_hub.models.ImageClassifier.from_preset(
    "resnet_50_imagenet",
    activation="softmax",
)
url = "https://upload.wikimedia.org/wikipedia/commons/a/aa/California_quail.jpg"
path = keras.utils.get_file(origin=url)
image = keras.utils.load_img(path)
preds = classifier.predict(np.array([image]))
print(keras_hub.utils.decode_imagenet_predictions(preds))

Load a Bert model and fine-tune it on IMDb movie reviews:

classifier = keras_hub.models.TextClassifier.from_preset(
    "bert_base_en_uncased",
    activation="softmax",
    num_classes=2,
)
imdb_train, imdb_test = tfds.load(
    "imdb_reviews",
    split=["train", "test"],
    as_supervised=True,
    batch_size=16,
)
classifier.fit(imdb_train, validation_data=imdb_test)
preds = classifier.predict(["What an amazing movie!", "A total waste of time."])
print(preds)

Installation

To install the latest KerasHub release with Keras 3, simply run:

pip install --upgrade keras-hub

Our text tokenizers are based on TensorFlow Text. Hence, if you are using any model which has language as a modality, you will have to run:

pip install --upgrade keras-hub[nlp]

To install the latest nightly changes for both KerasHub and Keras, you can use our nightly package.

pip install --upgrade keras-hub-nightly

Currently, installing KerasHub will always pull in TensorFlow for use of the tf.data API for preprocessing. When pre-processing with tf.data, training can still happen on any backend.

Visit the core Keras getting started page for more information on installing Keras 3, accelerator support, and compatibility with different frameworks.

Configuring your backend

If you have Keras 3 installed in your environment (see installation above), you can use KerasHub with any of JAX, TensorFlow and PyTorch. To do so, set the KERAS_BACKEND environment variable. For example:

export KERAS_BACKEND=jax

Or in Colab, with:

import os
os.environ["KERAS_BACKEND"] = "jax"

import keras_hub

Compatibility

We follow Semantic Versioning, and plan to provide backwards compatibility guarantees both for code and saved models built with our components. While we continue with pre-release 0.y.z development, we may break compatibility at any time and APIs should not be considered stable.

Disclaimer

KerasHub provides access to pre-trained models via the keras_hub.models API. These pre-trained models are provided on an "as is" basis, without warranties or conditions of any kind. The following underlying models are provided by third parties, and subject to separate licenses: BART, BLOOM, DeBERTa, DistilBERT, GPT-2, Llama, Mistral, OPT, RoBERTa, Whisper, and XLM-RoBERTa.

Citing KerasHub

If KerasHub helps your research, we appreciate your citations. Here is the BibTeX entry:

@misc{kerashub2024,
  title={KerasHub},
  author={Watson, Matthew, and  Chollet, Fran\c{c}ois and Sreepathihalli,
  Divyashree, and Saadat, Samaneh and Sampath, Ramesh, and Rasskin, Gabriel and
  and Zhu, Scott and Singh, Varun and Wood, Luke and Tan, Zhenyu and Stenbit,
  Ian and Qian, Chen, and Bischof, Jonathan and others},
  year={2024},
  howpublished={\url{https://github.com/keras-team/keras-hub}},
}

Acknowledgements

Thank you to all of our wonderful contributors!

Release files for keras-hub-nightly 0.22.0.dev202507180422

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for keras-hub-nightly 0.22.0.dev202507180422
File Size Uploaded
keras_hub_nightly-0.22.0.dev202507180422.tar.gz 643.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for keras-hub-nightly 0.22.0.dev202507180422
File Interpreter ABI Platform
keras_hub_nightly-0.22.0.dev202507180422-py3-none-any.whl Python 3 none any Details

Total release size: 1.6 MB

Release files / keras_hub_nightly-0.22.0.dev202507180422.tar.gz

Download URL keras_hub_nightly-0.22.0.dev202507180422.tar.gz
Size 643.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d8223a850834bfabdbd9245455a296163642083dd2d6ec1ff4188448f8fd2d09
BLAKE2b-256 checksum
How to use checksums
6025355c89ce8b82c35645d8dac32ce6eee630373bc1b252dbefb715d19178ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / keras_hub_nightly-0.22.0.dev202507180422-py3-none-any.whl

Download URL keras_hub_nightly-0.22.0.dev202507180422-py3-none-any.whl
Size 930.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
69359f0fc6daf3f55bd243e61778ac6b69c18697868daa45619b83103cf85876
BLAKE2b-256 checksum
How to use checksums
b25caf4d129154fedb8428801ba9ee5e280ee30efa55a056fd8385e4136011a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page