CLIPPreprocessor 类keras_hub.models.CLIPPreprocessor(
tokenizer,
image_converter=None,
sequence_length=77,
add_start_token=True,
add_end_token=True,
to_lower=True,
**kwargs
)
CLIP 预处理器。
此预处理层将执行 2 项操作
此预处理层旨在与 keras_hub.models.CLIPBackbone 一起使用。默认情况下,它将接收字符串和图像的批次,并返回 token ID 和调整大小后的图像。
参数
keras_hub.models.CLIPTokenizer 实例。keras_hub.models.CLIPImageConverter 实例。True,预处理器将在每个输入序列前添加分词器的起始词元。True,预处理器将在每个输入序列后附加分词器的结束词元。调用参数
"prompts" 和 "images" 键的字典,其中 "prompts" 是 tf.Tensor 或 Python 字符串列表,而 "images" 是图像张量。None,因为 SigLIP 不需要标签来计算损失。sequence_length。示例
# 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 方法CLIPPreprocessor.from_preset(preset, config_file="preprocessor.json", **kwargs)
从模型预设实例化一个 keras_hub.models.Preprocessor。
预设是一个包含配置、权重和其他文件资产的目录,用于保存和加载预训练模型。preset 可以作为以下之一传递:
'bert_base_en''kaggle://user/bert/keras/bert_base_en''hf://user/bert_base_en''./bert_base_en'对于任何 Preprocessor 子类,您可以运行 cls.presets.keys() 来列出该类上所有可用的内置预设。
由于一个给定模型通常有多个预处理类,因此应在特定的子类上调用此方法,例如 keras_hub.models.BertTextClassifierPreprocessor.from_preset()。
参数
示例
# 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",
)
| 预设 | 参数 | 描述 |
|---|---|---|
| clip_vit_base_patch16 | 149.62M | 1.5 亿参数,视觉 12 层,文本 12 层,补丁大小 16 的 CLIP 模型。 |
| clip_vit_base_patch32 | 151.28M | 1.51 亿参数,视觉 12 层,文本 12 层,补丁大小 32 的 CLIP 模型。 |
| clip_vit_b_32_laion2b_s34b_b79k | 151.28M | 1.51 亿参数,视觉 12 层,文本 12 层,补丁大小 32 的 Open CLIP 模型。 |
| clip_vit_large_patch14 | 427.62M | 4.28 亿参数,视觉 24 层,文本 12 层,补丁大小 14 的 CLIP 模型。 |
| clip_vit_large_patch14_336 | 427.94M | 4.28 亿参数,视觉 24 层,文本 12 层,补丁大小 14,图像大小 336 的 CLIP 模型。 |
| clip_vit_h_14_laion2b_s32b_b79k | 986.11M | 9.86 亿参数,视觉 32 层,文本 24 层,补丁大小 14 的 Open CLIP 模型。 |
| clip_vit_g_14_laion2b_s12b_b42k | 1.37B | 14 亿参数,视觉 40 层,文本 24 层,补丁大小 14 的 Open CLIP 模型。 |
| clip_vit_bigg_14_laion2b_39b_b160k | 2.54B | 25 亿参数,视觉 48 层,文本 32 层,补丁大小 14 的 Open CLIP 模型。 |
tokenizer 属性keras_hub.models.CLIPPreprocessor.tokenizer
用于对字符串进行分词的分词器。