CLIPPreprocessor
classkeras_hub.models.CLIPPreprocessor(
tokenizer,
image_converter=None,
sequence_length=77,
add_start_token=True,
add_end_token=True,
to_lower=True,
**kwargs
)
CLIP preprocessor.
This preprocessing layer will do 2 things:
This preprocessing layer is meant for use with
keras_hub.models.CLIPBackbone
. By default, it will take in batches of
strings and images, and return token ids and resized images.
Arguments
keras_hub.models.CLIPTokenizer
instance.keras_hub.models.CLIPImageConverter
instance.True
, the preprocessor will prepend the tokenizer
start token to each input sequence.True
, the preprocessor will append the tokenizer
end token to each input sequence.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.CLIPPreprocessor.from_preset(
"clip_vit_base_patch16"
)
# 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
methodCLIPPreprocessor.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 |
---|---|---|
clip_vit_base_patch16 | 149.62M | 150 million parameter, 12-layer for vision and 12-layer for text, patch size of 16, CLIP model. |
clip_vit_base_patch32 | 151.28M | 151 million parameter, 12-layer for vision and 12-layer for text, patch size of 32, CLIP model. |
clip_vit_b_32_laion2b_s34b_b79k | 151.28M | 151 million parameter, 12-layer for vision and 12-layer for text, patch size of 32, Open CLIP model. |
clip_vit_large_patch14 | 427.62M | 428 million parameter, 24-layer for vision and 12-layer for text, patch size of 14, CLIP model. |
clip_vit_large_patch14_336 | 427.94M | 428 million parameter, 24-layer for vision and 12-layer for text, patch size of 14, image size of 336, CLIP model. |
clip_vit_h_14_laion2b_s32b_b79k | 986.11M | 986 million parameter, 32-layer for vision and 24-layer for text, patch size of 14, Open CLIP model. |
clip_vit_g_14_laion2b_s12b_b42k | 1.37B | 1.4 billion parameter, 40-layer for vision and 24-layer for text, patch size of 14, Open CLIP model. |
clip_vit_bigg_14_laion2b_39b_b160k | 2.54B | 2.5 billion parameter, 48-layer for vision and 32-layer for text, patch size of 14, Open CLIP model. |
tokenizer
propertykeras_hub.models.CLIPPreprocessor.tokenizer
The tokenizer used to tokenize strings.