SigLIPPreprocessor
classkeras_hub.models.SigLIPPreprocessor(
tokenizer,
image_converter=None,
sequence_length=64,
add_start_token=False,
add_end_token=True,
canonicalize_text=True,
**kwargs
)
SigLIP preprocessor.
This preprocessing layer is meant for use with
keras_hub.models.SigLIPBackbone
. By default, it will take in batches of
strings and images, and return token ids and resized images.
Arguments
keras_hub.models.SigLIPTokenizer
instance.keras_hub.models.SigLIPImageConverter
instance.True
, the preprocessor will prepend the tokenizer
start token to each input sequence. Defaults to False
.True
, the preprocessor will append the tokenizer
end token to each input sequence. Defaults to True
.True
, the input strings will be canonicalized
(converted to lowercase, punctuation removed, and stripped).Call arguments
"prompts"
and "images"
keys, where "prompts"
is
tf.Tensor
or list of python strings and "images"
are the image
tensors.None
since SigLIP doesn't need the
label to calculate the loss.sequence_length
of
the layer.Examples
# Load the preprocessor from a preset.
preprocessor = keras_hub.models.SigLIPPreprocessor.from_preset(
"siglip_base_patch16_224"
)
# Tokenize the sentence and preprocess the image.
preprocessor(
{
"prompts": "The quick brown fox jumped.",
"images": np.ones(shape=(123, 123, 3)),
}
)
# Tokenize a batch of sentences and preprocess a batch of images.
preprocessor(
{
"prompts": ["The quick brown fox jumped.", "The fox slept."],
"images": np.ones(shape=(2, 123, 123, 3)),
}
)
from_preset
methodSigLIPPreprocessor.from_preset(preset, config_file="preprocessor.json", **kwargs)
Instantiate a keras_hub.models.Preprocessor
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:
'bert_base_en'
'kaggle://user/bert/keras/bert_base_en'
'hf://user/bert_base_en'
'./bert_base_en'
For any Preprocessor
subclass, you can run cls.presets.keys()
to
list all built-in presets available on the class.
As there are usually multiple preprocessing classes for a given model,
this method should be called on a specific subclass like
keras_hub.models.BertTextClassifierPreprocessor.from_preset()
.
Arguments
Examples
# Load a preprocessor for Gemma generation.
preprocessor = keras_hub.models.CausalLMPreprocessor.from_preset(
"gemma_2b_en",
)
# Load a preprocessor for Bert classification.
preprocessor = keras_hub.models.TextClassifierPreprocessor.from_preset(
"bert_base_en",
)
Preset | Parameters | Description |
---|---|---|
siglip_base_patch16_224 | 203.16M | 200 million parameter, image size 224, pre-trained on WebLi. |
siglip_base_patch16_256 | 203.20M | 200 million parameter, image size 256, pre-trained on WebLi. |
siglip_base_patch16_384 | 203.45M | 200 million parameter, image size 384, pre-trained on WebLi. |
siglip_base_patch16_512 | 203.79M | 200 million parameter, image size 512, pre-trained on WebLi. |
siglip_base_patch16_256_multilingual | 370.63M | 370 million parameter, image size 256, pre-trained on WebLi. |
siglip2_base_patch16_224 | 375.19M | 375 million parameter, patch size 16, image size 224, pre-trained on WebLi. |
siglip2_base_patch16_256 | 375.23M | 375 million parameter, patch size 16, image size 256, pre-trained on WebLi. |
siglip2_base_patch32_256 | 376.86M | 376 million parameter, patch size 32, image size 256, pre-trained on WebLi. |
siglip2_base_patch16_384 | 376.86M | 376 million parameter, patch size 16, image size 384, pre-trained on WebLi. |
siglip_large_patch16_256 | 652.15M | 652 million parameter, image size 256, pre-trained on WebLi. |
siglip_large_patch16_384 | 652.48M | 652 million parameter, image size 384, pre-trained on WebLi. |
siglip_so400m_patch14_224 | 877.36M | 877 million parameter, image size 224, shape-optimized version, pre-trained on WebLi. |
siglip_so400m_patch14_384 | 877.96M | 877 million parameter, image size 384, shape-optimized version, pre-trained on WebLi. |
siglip2_large_patch16_256 | 881.53M | 881 million parameter, patch size 16, image size 256, pre-trained on WebLi. |
siglip2_large_patch16_384 | 881.86M | 881 million parameter, patch size 16, image size 384, pre-trained on WebLi. |
siglip2_large_patch16_512 | 882.31M | 882 million parameter, patch size 16, image size 512, pre-trained on WebLi. |
siglip_so400m_patch16_256_i18n | 1.13B | 1.1 billion parameter, image size 256, shape-optimized version, pre-trained on WebLi. |
siglip2_so400m_patch14_224 | 1.14B | 1.1 billion parameter, patch size 14, image size 224, shape-optimized version, pre-trained on WebLi. |
siglip2_so400m_patch16_256 | 1.14B | 1.1 billion parameter, patch size 16, image size 256, shape-optimized version, pre-trained on WebLi. |
siglip2_so400m_patch14_384 | 1.14B | 1.1 billion parameter, patch size 14, image size 224, shape-optimized version, pre-trained on WebLi. |
siglip2_so400m_patch16_384 | 1.14B | 1.1 billion parameter, patch size 16, image size 384, shape-optimized version, pre-trained on WebLi. |
siglip2_so400m_patch16_512 | 1.14B | 1.1 billion parameter, patch size 16, image size 512, shape-optimized version, pre-trained on WebLi. |
siglip2_giant_opt_patch16_256 | 1.87B | 1.8 billion parameter, patch size 16, image size 256, pre-trained on WebLi. |
siglip2_giant_opt_patch16_384 | 1.87B | 1.8 billion parameter, patch size 16, image size 384, pre-trained on WebLi. |
tokenizer
propertykeras_hub.models.SigLIPPreprocessor.tokenizer
The tokenizer used to tokenize strings.