upload
Browse files- 0_CLIPModel/config.json +162 -0
- 0_CLIPModel/merges.txt +0 -0
- 0_CLIPModel/preprocessor_config.json +20 -0
- 0_CLIPModel/pytorch_model.bin +3 -0
- 0_CLIPModel/special_tokens_map.json +1 -0
- 0_CLIPModel/tokenizer.json +0 -0
- 0_CLIPModel/tokenizer_config.json +1 -0
- 0_CLIPModel/vocab.json +0 -0
- README.md +48 -0
- config_sentence_transformers.json +7 -0
- modules.json +8 -0
0_CLIPModel/config.json
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "openai/clip-vit-base-patch16",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"CLIPModel"
|
| 5 |
+
],
|
| 6 |
+
"initializer_factor": 1.0,
|
| 7 |
+
"logit_scale_init_value": 2.6592,
|
| 8 |
+
"model_type": "clip",
|
| 9 |
+
"projection_dim": 512,
|
| 10 |
+
"text_config": {
|
| 11 |
+
"_name_or_path": "",
|
| 12 |
+
"add_cross_attention": false,
|
| 13 |
+
"architectures": null,
|
| 14 |
+
"attention_dropout": 0.0,
|
| 15 |
+
"bad_words_ids": null,
|
| 16 |
+
"bos_token_id": 0,
|
| 17 |
+
"chunk_size_feed_forward": 0,
|
| 18 |
+
"cross_attention_hidden_size": null,
|
| 19 |
+
"decoder_start_token_id": null,
|
| 20 |
+
"diversity_penalty": 0.0,
|
| 21 |
+
"do_sample": false,
|
| 22 |
+
"dropout": 0.0,
|
| 23 |
+
"early_stopping": false,
|
| 24 |
+
"encoder_no_repeat_ngram_size": 0,
|
| 25 |
+
"eos_token_id": 2,
|
| 26 |
+
"exponential_decay_length_penalty": null,
|
| 27 |
+
"finetuning_task": null,
|
| 28 |
+
"forced_bos_token_id": null,
|
| 29 |
+
"forced_eos_token_id": null,
|
| 30 |
+
"hidden_act": "quick_gelu",
|
| 31 |
+
"hidden_size": 512,
|
| 32 |
+
"id2label": {
|
| 33 |
+
"0": "LABEL_0",
|
| 34 |
+
"1": "LABEL_1"
|
| 35 |
+
},
|
| 36 |
+
"initializer_factor": 1.0,
|
| 37 |
+
"initializer_range": 0.02,
|
| 38 |
+
"intermediate_size": 2048,
|
| 39 |
+
"is_decoder": false,
|
| 40 |
+
"is_encoder_decoder": false,
|
| 41 |
+
"label2id": {
|
| 42 |
+
"LABEL_0": 0,
|
| 43 |
+
"LABEL_1": 1
|
| 44 |
+
},
|
| 45 |
+
"layer_norm_eps": 1e-05,
|
| 46 |
+
"length_penalty": 1.0,
|
| 47 |
+
"max_length": 20,
|
| 48 |
+
"max_position_embeddings": 77,
|
| 49 |
+
"min_length": 0,
|
| 50 |
+
"model_type": "clip_text_model",
|
| 51 |
+
"no_repeat_ngram_size": 0,
|
| 52 |
+
"num_attention_heads": 8,
|
| 53 |
+
"num_beam_groups": 1,
|
| 54 |
+
"num_beams": 1,
|
| 55 |
+
"num_hidden_layers": 12,
|
| 56 |
+
"num_return_sequences": 1,
|
| 57 |
+
"output_attentions": false,
|
| 58 |
+
"output_hidden_states": false,
|
| 59 |
+
"output_scores": false,
|
| 60 |
+
"pad_token_id": 1,
|
| 61 |
+
"prefix": null,
|
| 62 |
+
"problem_type": null,
|
| 63 |
+
"pruned_heads": {},
|
| 64 |
+
"remove_invalid_values": false,
|
| 65 |
+
"repetition_penalty": 1.0,
|
| 66 |
+
"return_dict": true,
|
| 67 |
+
"return_dict_in_generate": false,
|
| 68 |
+
"sep_token_id": null,
|
| 69 |
+
"task_specific_params": null,
|
| 70 |
+
"temperature": 1.0,
|
| 71 |
+
"tie_encoder_decoder": false,
|
| 72 |
+
"tie_word_embeddings": true,
|
| 73 |
+
"tokenizer_class": null,
|
| 74 |
+
"top_k": 50,
|
| 75 |
+
"top_p": 1.0,
|
| 76 |
+
"torch_dtype": null,
|
| 77 |
+
"torchscript": false,
|
| 78 |
+
"transformers_version": "4.18.0",
|
| 79 |
+
"typical_p": 1.0,
|
| 80 |
+
"use_bfloat16": false,
|
| 81 |
+
"vocab_size": 49408
|
| 82 |
+
},
|
| 83 |
+
"text_config_dict": null,
|
| 84 |
+
"torch_dtype": "float32",
|
| 85 |
+
"transformers_version": null,
|
| 86 |
+
"vision_config": {
|
| 87 |
+
"_name_or_path": "",
|
| 88 |
+
"add_cross_attention": false,
|
| 89 |
+
"architectures": null,
|
| 90 |
+
"attention_dropout": 0.0,
|
| 91 |
+
"bad_words_ids": null,
|
| 92 |
+
"bos_token_id": null,
|
| 93 |
+
"chunk_size_feed_forward": 0,
|
| 94 |
+
"cross_attention_hidden_size": null,
|
| 95 |
+
"decoder_start_token_id": null,
|
| 96 |
+
"diversity_penalty": 0.0,
|
| 97 |
+
"do_sample": false,
|
| 98 |
+
"dropout": 0.0,
|
| 99 |
+
"early_stopping": false,
|
| 100 |
+
"encoder_no_repeat_ngram_size": 0,
|
| 101 |
+
"eos_token_id": null,
|
| 102 |
+
"exponential_decay_length_penalty": null,
|
| 103 |
+
"finetuning_task": null,
|
| 104 |
+
"forced_bos_token_id": null,
|
| 105 |
+
"forced_eos_token_id": null,
|
| 106 |
+
"hidden_act": "quick_gelu",
|
| 107 |
+
"hidden_size": 768,
|
| 108 |
+
"id2label": {
|
| 109 |
+
"0": "LABEL_0",
|
| 110 |
+
"1": "LABEL_1"
|
| 111 |
+
},
|
| 112 |
+
"image_size": 224,
|
| 113 |
+
"initializer_factor": 1.0,
|
| 114 |
+
"initializer_range": 0.02,
|
| 115 |
+
"intermediate_size": 3072,
|
| 116 |
+
"is_decoder": false,
|
| 117 |
+
"is_encoder_decoder": false,
|
| 118 |
+
"label2id": {
|
| 119 |
+
"LABEL_0": 0,
|
| 120 |
+
"LABEL_1": 1
|
| 121 |
+
},
|
| 122 |
+
"layer_norm_eps": 1e-05,
|
| 123 |
+
"length_penalty": 1.0,
|
| 124 |
+
"max_length": 20,
|
| 125 |
+
"min_length": 0,
|
| 126 |
+
"model_type": "clip_vision_model",
|
| 127 |
+
"no_repeat_ngram_size": 0,
|
| 128 |
+
"num_attention_heads": 12,
|
| 129 |
+
"num_beam_groups": 1,
|
| 130 |
+
"num_beams": 1,
|
| 131 |
+
"num_hidden_layers": 12,
|
| 132 |
+
"num_return_sequences": 1,
|
| 133 |
+
"output_attentions": false,
|
| 134 |
+
"output_hidden_states": false,
|
| 135 |
+
"output_scores": false,
|
| 136 |
+
"pad_token_id": null,
|
| 137 |
+
"patch_size": 16,
|
| 138 |
+
"prefix": null,
|
| 139 |
+
"problem_type": null,
|
| 140 |
+
"pruned_heads": {},
|
| 141 |
+
"remove_invalid_values": false,
|
| 142 |
+
"repetition_penalty": 1.0,
|
| 143 |
+
"return_dict": true,
|
| 144 |
+
"return_dict_in_generate": false,
|
| 145 |
+
"sep_token_id": null,
|
| 146 |
+
"task_specific_params": null,
|
| 147 |
+
"temperature": 1.0,
|
| 148 |
+
"tie_encoder_decoder": false,
|
| 149 |
+
"tie_word_embeddings": true,
|
| 150 |
+
"tokenizer_class": null,
|
| 151 |
+
"top_k": 50,
|
| 152 |
+
"top_p": 1.0,
|
| 153 |
+
"torch_dtype": null,
|
| 154 |
+
"torchscript": false,
|
| 155 |
+
"transformers_version": "4.18.0",
|
| 156 |
+
"typical_p": 1.0,
|
| 157 |
+
"use_bfloat16": false
|
| 158 |
+
},
|
| 159 |
+
"vision_config_dict": {
|
| 160 |
+
"patch_size": 16
|
| 161 |
+
}
|
| 162 |
+
}
|
0_CLIPModel/merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
0_CLIPModel/preprocessor_config.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"crop_size": 224,
|
| 3 |
+
"do_center_crop": true,
|
| 4 |
+
"do_normalize": true,
|
| 5 |
+
"do_resize": true,
|
| 6 |
+
"feature_extractor_type": "CLIPFeatureExtractor",
|
| 7 |
+
"image_mean": [
|
| 8 |
+
0.48145466,
|
| 9 |
+
0.4578275,
|
| 10 |
+
0.40821073
|
| 11 |
+
],
|
| 12 |
+
"image_std": [
|
| 13 |
+
0.26862954,
|
| 14 |
+
0.26130258,
|
| 15 |
+
0.27577711
|
| 16 |
+
],
|
| 17 |
+
"processor_class": "CLIPProcessor",
|
| 18 |
+
"resample": 3,
|
| 19 |
+
"size": 224
|
| 20 |
+
}
|
0_CLIPModel/pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:66d22a979777b2936ec3f52e25757ab93673ebf7bc0d523789df3a4355db8a44
|
| 3 |
+
size 598613921
|
0_CLIPModel/special_tokens_map.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"bos_token": {"content": "<|startoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "eos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "unk_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "pad_token": "<|endoftext|>"}
|
0_CLIPModel/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
0_CLIPModel/tokenizer_config.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"unk_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "bos_token": {"content": "<|startoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "eos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "pad_token": "<|endoftext|>", "errors": "replace", "add_prefix_space": false, "do_lower_case": true, "name_or_path": "openai/clip-vit-base-patch16", "model_max_length": 77, "special_tokens_map_file": "./special_tokens_map.json", "tokenizer_class": "CLIPTokenizer", "processor_class": "CLIPProcessor"}
|
0_CLIPModel/vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pipeline_tag: sentence-similarity
|
| 3 |
+
tags:
|
| 4 |
+
- sentence-transformers
|
| 5 |
+
- feature-extraction
|
| 6 |
+
- sentence-similarity
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
# clip-ViT-B-16
|
| 10 |
+
|
| 11 |
+
This is the Image & Text model [CLIP](https://arxiv.org/abs/2103.00020), which maps text and images to a shared vector space. For applications of the models, have a look in our documentation [SBERT.net - Image Search](https://www.sbert.net/examples/applications/image-search/README.html)
|
| 12 |
+
|
| 13 |
+
## Usage
|
| 14 |
+
|
| 15 |
+
After installing [sentence-transformers](https://sbert.net) (`pip install sentence-transformers`), the usage of this model is easy:
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
```python
|
| 19 |
+
from sentence_transformers import SentenceTransformer, util
|
| 20 |
+
from PIL import Image
|
| 21 |
+
|
| 22 |
+
#Load CLIP model
|
| 23 |
+
model = SentenceTransformer('clip-ViT-B-16')
|
| 24 |
+
|
| 25 |
+
#Encode an image:
|
| 26 |
+
img_emb = model.encode(Image.open('two_dogs_in_snow.jpg'))
|
| 27 |
+
|
| 28 |
+
#Encode text descriptions
|
| 29 |
+
text_emb = model.encode(['Two dogs in the snow', 'A cat on a table', 'A picture of London at night'])
|
| 30 |
+
|
| 31 |
+
#Compute cosine similarities
|
| 32 |
+
cos_scores = util.cos_sim(img_emb, text_emb)
|
| 33 |
+
print(cos_scores)
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
See our [SBERT.net - Image Search](https://www.sbert.net/examples/applications/image-search/README.html) documentation for more examples how the model can be used for image search, zero-shot image classification, image clustering and image deduplication.
|
| 37 |
+
|
| 38 |
+
## Performance
|
| 39 |
+
|
| 40 |
+
In the following table we find the zero-shot ImageNet validation set accuracy:
|
| 41 |
+
|
| 42 |
+
| Model | Top 1 Performance |
|
| 43 |
+
| --- | :---: |
|
| 44 |
+
| [clip-ViT-B-32](https://huggingface.co/sentence-transformers/clip-ViT-B-32) | 63.3 |
|
| 45 |
+
| [clip-ViT-B-16](https://huggingface.co/sentence-transformers/clip-ViT-B-16) | 68.1 |
|
| 46 |
+
| [clip-ViT-L-14](https://huggingface.co/sentence-transformers/clip-ViT-L-14) | 75.4 |
|
| 47 |
+
|
| 48 |
+
For a multilingual version of the CLIP model for 50+ languages have a look at: [clip-ViT-B-32-multilingual-v1](https://huggingface.co/sentence-transformers/clip-ViT-B-32-multilingual-v1)
|
config_sentence_transformers.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"__version__": {
|
| 3 |
+
"sentence_transformers": "2.2.0",
|
| 4 |
+
"transformers": "4.18.0",
|
| 5 |
+
"pytorch": "1.11.0"
|
| 6 |
+
}
|
| 7 |
+
}
|
modules.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"idx": 0,
|
| 4 |
+
"name": "0",
|
| 5 |
+
"path": "0_CLIPModel",
|
| 6 |
+
"type": "sentence_transformers.models.CLIPModel"
|
| 7 |
+
}
|
| 8 |
+
]
|