C.W.K.
Stream
Lesson 03 of 05 · published

KerasCV, KerasHub, and the Keras 3 Convergence

~13 min · keras-cv, keras-hub, keras3, multi-backend

Level 0Level 0
0 XP0/78 lessons0/17 achievements
0/100 XP to next level100 XP to go0% complete

The unifying layer above the framework wars

KerasCV provides modular computer vision components — pretrained backbones, preprocessing layers, augmentation pipelines, complete task models — built on Keras 3 for multi-backend compatibility.

KerasHub (was KerasNLP) provides pretrained language models including LLaMA 3, Gemma, BERT, GPT-2, Whisper. One-line load + fine-tune.

Keras 3 is the major architectural shift: Keras runs on TensorFlow, JAX, AND PyTorch as backends. The convergence layer that resolves the TF vs JAX research tension. Write the model once, switch backends with one env var. Use keras.ops instead of tf.* / jnp.* / torch.* for backend-agnostic math.

Code

KerasCV — object detection, augmentation·python
import keras_cv
import keras

# pip install keras-cv

# YOLOv8 object detection (COCO pretrained)
yolo = keras_cv.models.YOLOV8Detector.from_preset(
    "yolo_v8_m_pascalvoc", num_classes=20,
)

# Image classification with pretrained backbone
backbone = keras_cv.models.EfficientNetV2Backbone.from_preset(
    "efficientnetv2_s_imagenet"
)
model = keras_cv.models.ImageClassifier(
    backbone=backbone, num_classes=10,
)

# Advanced data augmentation
augmenter = keras_cv.layers.Augmenter(layers=[
    keras_cv.layers.RandomFlip(),
    keras_cv.layers.RandAugment(value_range=(0, 255)),
    keras_cv.layers.MixUp(alpha=0.2),
    keras_cv.layers.CutMix(alpha=0.2),
])
KerasHub — LLM in three lines·python
import keras_hub
import tensorflow as tf

# pip install keras-hub

# BERT fine-tuning (one-liner)
classifier = keras_hub.models.BertTextClassifier.from_preset(
    "bert_base_en_uncased", num_classes=5,
)
classifier.compile(
    optimizer=tf.keras.optimizers.Adam(5e-5),
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy'],
)
classifier.fit(train_ds, validation_data=val_ds, epochs=3)

# LLM text generation
llm = keras_hub.models.Llama3CausalLM.from_preset("llama3_instruct_8b_en")
print(llm.generate("Explain TensorFlow in one sentence:", max_length=64))

# Whisper speech-to-text
whisper = keras_hub.models.WhisperAudioToText.from_preset("whisper_base_en")
Keras 3 — backend-agnostic code·python
import os
os.environ["KERAS_BACKEND"] = "jax"   # or "tensorflow", "torch"

import keras
from keras import ops

class MyLayer(keras.layers.Layer):
    def call(self, x):
        # Use keras.ops, NOT tf.* / jnp.* / torch.*
        # These work identically across all three backends
        x = ops.matmul(x, self.kernel)
        x = ops.relu(x)
        return ops.softmax(x)

# Train with JAX for TPU performance
os.environ["KERAS_BACKEND"] = "jax"
model = keras.Sequential([...])
model.fit(train_data, epochs=10)

# Export framework-agnostically
model.save("model.keras")

# Reload and serve with TensorFlow
os.environ["KERAS_BACKEND"] = "tensorflow"
production_model = keras.saving.load_model("model.keras")

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.