From 70d8afaa98d3442e114af8871b3614359c4b1905 Mon Sep 17 00:00:00 2001 From: Matt Watson <1389937+mattdangerw@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:39:37 -0800 Subject: [PATCH 1/2] Update README.md Sync content with keras.io --- README.md | 113 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 54ce9324b8..0f3e5a04bb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# KerasHub: Multi-framework Models +# KerasHub: Multi-framework Pretrained Models [![](https://github.com/keras-team/keras-hub/workflows/Tests/badge.svg?branch=master)](https://github.com/keras-team/keras-hub/actions?query=workflow%3ATests+branch%3Amaster) ![Python](https://img.shields.io/badge/python-v3.9.0+-success.svg) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/keras-team/keras-hub/issues) @@ -7,98 +7,115 @@ > 📢 KerasNLP is now KerasHub! 📢 Read > [the announcement](https://github.com/keras-team/keras-hub/issues/1831). -KerasHub is a library that supports natural language processing, computer -vision, audio, and multimodal backbones and task models, working natively with -TensorFlow, JAX, or PyTorch. KerasHub provides a repository of pre-trained -models and a collection of lower-level building blocks for these tasks. Built -on Keras 3, models can be trained and serialized in any framework and re-used -in another without costly migrations. +**KerasHub** is a pretrained modeling library that aims to be simple, flexible, +and fast. The library provides [Keras 3](https://keras.io/keras_3/) +implementations of popular model architectures, paired with a collection of +pretrained checkpoints available on [Kaggle Models](https://kaggle.com/models/). +Models can be used for both training and inference, on any of the TensorFlow, +Jax, and Torch backends. -This library is an extension of the core Keras API; all high-level modules are -Layers and Models that receive that same level of polish as core Keras. -If you are familiar with Keras, congratulations! You already understand most of -KerasHub. +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](https://keras.io/guides/keras_hub/getting_started) -to start learning our API. Browse our models on -[Kaggle](https://www.kaggle.com/organizations/keras/models). -We welcome contributions. +to start learning our API. ## Quick Links ### For everyone -- [Home Page](https://keras.io/keras_hub) -- [Developer Guides](https://keras.io/guides/keras_hub) -- [API Reference](https://keras.io/api/keras_hub) -- [Pre-trained Models](https://www.kaggle.com/organizations/keras/models) +- [Home page](https://keras.io/keras_hub) +- [Getting started](https://keras.io/keras_hub/getting_started) +- [Guides](https://keras.io/keras_hub/guides) +- [API documentation](https://keras.io/keras_hub/api) +- [Pre-trained models](https://keras.io/keras_hub/presets/) ### For contributors +- [Call for Contributions](https://github.com/keras-team/keras-hub/issues/1835) +- [Roadmap](https://github.com/keras-team/keras-hub/issues/1836) - [Contributing Guide](CONTRIBUTING.md) -- [Roadmap](ROADMAP.md) - [Style Guide](STYLE_GUIDE.md) - [API Design Guide](API_DESIGN_GUIDE.md) -- [Call for Contributions](https://github.com/keras-team/keras-hub/issues?q=is%3Aissue+is%3Aopen+label%3A%22contributions+welcome%22) ## Quickstart -Fine-tune a BERT classifier on IMDb movie reviews: +Choose a backend: ```python import os os.environ["KERAS_BACKEND"] = "jax" # Or "tensorflow" or "torch"! +``` + +Import KerasHub and other libraries: +```python +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: + +```python +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: + +```python +classifier = keras_hub.models.BertClassifier.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, ) - -# Load a BERT model. -classifier = keras_hub.models.Classifier.from_preset( - "bert_base_en", - num_classes=2, - activation="softmax", -) - -# Fine-tune on IMDb movie reviews. classifier.fit(imdb_train, validation_data=imdb_test) -# Predict two new examples. -classifier.predict(["What an amazing movie!", "A total waste of my time."]) +preds = classifier.predict(["What an amazing movie!", "A total waste of time."]) +print(preds) ``` -Try it out [in a colab](https://colab.research.google.com/drive/1gSWkh3yOLwmKAaNh2dQQ6kQIlnGte7P2?usp=sharing). -For more in depth guides and examples, visit -[keras.io/keras_hub](https://keras.io/keras_hub/). - ## Installation -To try out the latest version of KerasHub, you can use -our nightly package: +To install the latest KerasHub release with Keras 3, simply run: -```bash -pip install keras-hub ``` +pip install --upgrade keras-hub +``` + +To install the latest nightly changes for both KerasHub and Keras, you can use +our nightly package. -KerasHub currently requires TensorFlow to be installed for use of the -`tf.data` API for preprocessing. Even when pre-processing with `tf.data`, -training can still happen on any backend. +``` +pip install --upgrade keras-hub-nightly +``` -Read [Getting started with Keras](https://keras.io/getting_started/) for more -information on installing Keras 3 and compatibility with different frameworks. +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. -> [!IMPORTANT] -> We recommend using KerasHub with TensorFlow 2.16 or later, as TF 2.16 packages -> Keras 3 by default. +Visit the [core Keras getting started page](https://keras.io/getting_started/) +for more information on installing Keras 3, accelerator support, and +compatibility with different frameworks. ## Configuring your backend From 4753b3e54a6bbbc93c9c6d80dff540239ec91290 Mon Sep 17 00:00:00 2001 From: Matt Watson <1389937+mattdangerw@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:45:46 -0800 Subject: [PATCH 2/2] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0f3e5a04bb..6368571388 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ and fast. The library provides [Keras 3](https://keras.io/keras_3/) implementations of popular model architectures, paired with a collection of pretrained checkpoints available on [Kaggle Models](https://kaggle.com/models/). -Models can be used for both training and inference, on any of the TensorFlow, -Jax, and Torch backends. +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,