DiffusionGemmaImageConverter

[source]

DiffusionGemmaImageConverter class

keras_hub.layers.DiffusionGemmaImageConverter(
    patch_size=16, max_soft_tokens=280, pooling_kernel_size=3, **kwargs
)

Preprocess raw images for Gemma4 vision inputs.

Resizes images using aspect-ratio-preserving scaling to the nearest valid resolution (a multiple of patch_size * pooling_kernel_size), then applies optional per-channel rescaling and offset. The output is a dict with keys "pixel_values" (the flattened patch tensor) and "pixel_position_ids" (2-D (x, y) position indices for each patch).

Arguments

  • patch_size: int. Size of each square patch in pixels. Defaults to 16.
  • max_soft_tokens: int. Maximum number of pooled soft tokens per image. Controls the target resolution: the image is scaled so that the total number of patches after pooling does not exceed this value. Defaults to 280.
  • pooling_kernel_size: int. Spatial pooling kernel size applied after the vision encoder. Used together with patch_size to compute valid target dimensions. Defaults to 3.
  • **kwargs: Additional keyword arguments forwarded to keras_hub.layers.ImageConverter, e.g. scale, offset.

[source]

from_preset method

DiffusionGemmaImageConverter.from_preset(preset, **kwargs)

Instantiate a keras_hub.layers.ImageConverter from a model preset.

A preset is a directory of configs, weights and other file assets used to save and load a pre-trained model. The preset can be passed as one of:

  1. a built-in preset identifier like 'pali_gemma_3b_224'
  2. a Kaggle Models handle like 'kaggle://user/paligemma/keras/pali_gemma_3b_224'
  3. a Hugging Face handle like 'hf://user/pali_gemma_3b_224'
  4. a path to a local preset directory like './pali_gemma_3b_224'

You can run cls.presets.keys() to list all built-in presets available on the class.

Arguments

  • preset: string. A built-in preset identifier, a Kaggle Models handle, a Hugging Face handle, or a path to a local directory.
  • load_weights: bool. If True, the weights will be loaded into the model architecture. If False, the weights will be randomly initialized.

Examples

batch = np.random.randint(0, 256, size=(2, 512, 512, 3))

# Resize images for `"pali_gemma_3b_224"`.
converter = keras_hub.layers.ImageConverter.from_preset(
    "pali_gemma_3b_224"
)
converter(batch) # # Output shape (2, 224, 224, 3)

# Resize images for `"pali_gemma_3b_448"` without cropping.
converter = keras_hub.layers.ImageConverter.from_preset(
    "pali_gemma_3b_448",
    crop_to_aspect_ratio=False,
)
converter(batch) # # Output shape (2, 448, 448, 3)
Preset Parameters Description
diffusion_gemma_26b_a4b_it 25.82B DiffusionGemma 26B MoE instruction-tuned model. 25.8B total parameters (3.8B active), 30 layers, 128 experts.