SmolVLM2VisionEncoder classkeras_hub.models.SmolVLM2VisionEncoder(
image_size,
patch_size,
hidden_dim,
intermediate_dim,
num_layers,
num_heads,
num_channels=3,
layer_norm_epsilon=1e-06,
attention_dropout=0.0,
dtype=None,
**kwargs
)
SmolVLM2 vision encoder (Idefics3-style SigLIP ViT).
A vision transformer that embeds images into patch features with a
Conv2D patch embedding plus a learned, raster-order position
embedding, followed by a stack of encoder blocks and a final
LayerNorm. Inputs must already be square and match image_size;
SmolVLM2ImageConverter is responsible for resizing and splitting
images to that size.
Arguments
3.1e-6.0.0.keras.mixed_precision.DTypePolicy.Examples
# Randomly initialized vision encoder.
encoder = keras_hub.models.SmolVLM2VisionEncoder(
image_size=384,
patch_size=14,
hidden_dim=1152,
intermediate_dim=4304,
num_layers=27,
num_heads=16,
)
images = np.random.rand(1, 384, 384, 3).astype("float32")
output = encoder({"pixel_values": images})
# output.shape == (1, 729, 1152)
from_preset methodSmolVLM2VisionEncoder.from_preset(preset, load_weights=True, **kwargs)
Instantiate a keras_hub.models.Backbone 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 a
one of:
'bert_base_en''kaggle://user/bert/keras/bert_base_en''hf://user/bert_base_en''modelscope://user/bert_base_en''./bert_base_en'This constructor can be called in one of two ways. Either from the base
class like keras_hub.models.Backbone.from_preset(), or from
a model class like keras_hub.models.GemmaBackbone.from_preset().
If calling from the base class, the subclass of the returning object
will be inferred from the config in the preset directory.
For any Backbone subclass, you can run cls.presets.keys() to list
all built-in presets available on the class.
Arguments
True, the weights will be loaded into the
model architecture. If False, the weights will be randomly
initialized.Examples
# Load a Gemma backbone with pre-trained weights.
model = keras_hub.models.Backbone.from_preset(
"gemma_2b_en",
)
# Load a Bert backbone with a pre-trained config and random weights.
model = keras_hub.models.Backbone.from_preset(
"bert_base_en",
load_weights=False,
)