Safetensors
siglip
vision
m-toman commited on
Commit
2ff23fd
·
verified ·
1 Parent(s): 111b6f2

Upload text model tensors

Browse files
README.md ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - vision
5
+ widget:
6
+ - src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/cat-dog-music.png
7
+ candidate_labels: playing music, playing sports
8
+ example_title: Cat & Dog
9
+ ---
10
+
11
+ # Text tower of `google/siglip-base-patch16-512`
12
+
13
+ > **Note:** This is a stripped-down copy of [`google/siglip-base-patch16-512`](https://huggingface.co/google/siglip-base-patch16-512) containing only the **text tower**. It encodes text queries into the shared embedding space and is meant to be loaded on its own at **retrieval** time, separately from the other tower. Splitting the towers lets you load only the half you need, saving memory and load time.
14
+ >
15
+ > The vision tower (used at indexing time) lives in [`m-toman/siglip-base-patch16-512-vision`](https://huggingface.co/m-toman/siglip-base-patch16-512-vision).
16
+
17
+ ---
18
+
19
+ ## Original model card
20
+
21
+ # SigLIP (base-sized model)
22
+
23
+ SigLIP model pre-trained on WebLi at resolution 512x512. It was introduced in the paper [Sigmoid Loss for Language Image Pre-Training](https://arxiv.org/abs/2303.15343) by Zhai et al. and first released in [this repository](https://github.com/google-research/big_vision).
24
+
25
+ Disclaimer: The team releasing SigLIP did not write a model card for this model so this model card has been written by the Hugging Face team.
26
+
27
+ ## Model description
28
+
29
+ SigLIP is [CLIP](https://huggingface.co/docs/transformers/model_doc/clip), a multimodal model, with a better loss function. The sigmoid loss operates solely on image-text pairs and does not require a global view of the pairwise similarities for normalization. This allows further scaling up the batch size, while also performing better at smaller batch sizes.
30
+
31
+ A TLDR of SigLIP by one of the authors can be found [here](https://twitter.com/giffmana/status/1692641733459267713).
32
+
33
+ ## Intended uses & limitations
34
+
35
+ You can use the raw model for tasks like zero-shot image classification and image-text retrieval. See the [model hub](https://huggingface.co/models?search=google/siglip) to look for
36
+ other versions on a task that interests you.
37
+
38
+ ### How to use
39
+
40
+ Here is how to use this model to perform zero-shot image classification:
41
+
42
+ ```python
43
+ from PIL import Image
44
+ import requests
45
+ from transformers import AutoProcessor, AutoModel
46
+ import torch
47
+
48
+ model = AutoModel.from_pretrained("google/siglip-base-patch16-512")
49
+ processor = AutoProcessor.from_pretrained("google/siglip-base-patch16-512")
50
+
51
+ url = "http://images.cocodataset.org/val2017/000000039769.jpg"
52
+ image = Image.open(requests.get(url, stream=True).raw)
53
+
54
+ texts = ["a photo of 2 cats", "a photo of 2 dogs"]
55
+ inputs = processor(text=texts, images=image, padding="max_length", return_tensors="pt")
56
+
57
+ with torch.no_grad():
58
+ outputs = model(**inputs)
59
+
60
+ logits_per_image = outputs.logits_per_image
61
+ probs = torch.sigmoid(logits_per_image) # these are the probabilities
62
+ print(f"{probs[0][0]:.1%} that image 0 is '{texts[0]}'")
63
+ ```
64
+
65
+ Alternatively, one can leverage the pipeline API which abstracts away the complexity for the user:
66
+
67
+ ```python
68
+ from transformers import pipeline
69
+ from PIL import Image
70
+ import requests
71
+
72
+ # load pipe
73
+ image_classifier = pipeline(task="zero-shot-image-classification", model="google/siglip-base-patch16-512")
74
+
75
+ # load image
76
+ url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
77
+ image = Image.open(requests.get(url, stream=True).raw)
78
+
79
+ # inference
80
+ outputs = image_classifier(image, candidate_labels=["2 cats", "a plane", "a remote"])
81
+ outputs = [{"score": round(output["score"], 4), "label": output["label"] } for output in outputs]
82
+ print(outputs)
83
+ ```
84
+ For more code examples, we refer to the [documentation](https://huggingface.co/transformers/main/model_doc/siglip.html#).
85
+
86
+ ## Training procedure
87
+
88
+ ### Training data
89
+
90
+ SigLIP is pre-trained on the English image-text pairs of the WebLI dataset [(Chen et al., 2023)](https://arxiv.org/abs/2209.06794).
91
+
92
+ ### Preprocessing
93
+
94
+ Images are resized/rescaled to the same resolution (512x512) and normalized across the RGB channels with mean (0.5, 0.5, 0.5) and standard deviation (0.5, 0.5, 0.5).
95
+
96
+ Texts are tokenized and padded to the same length (64 tokens).
97
+
98
+ ### Compute
99
+
100
+ The model was trained on 16 TPU-v4 chips for three days.
101
+
102
+ ## Evaluation results
103
+
104
+ Evaluation of SigLIP compared to CLIP is shown below (taken from the paper).
105
+
106
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/siglip_table.jpeg"
107
+ alt="drawing" width="600"/>
108
+
109
+ ### BibTeX entry and citation info
110
+
111
+ ```bibtex
112
+ @misc{zhai2023sigmoid,
113
+ title={Sigmoid Loss for Language Image Pre-Training},
114
+ author={Xiaohua Zhai and Basil Mustafa and Alexander Kolesnikov and Lucas Beyer},
115
+ year={2023},
116
+ eprint={2303.15343},
117
+ archivePrefix={arXiv},
118
+ primaryClass={cs.CV}
119
+ }
120
+ ```
config.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "SiglipModel"
4
+ ],
5
+ "initializer_factor": 1.0,
6
+ "model_type": "siglip",
7
+ "text_config": {
8
+ "model_type": "siglip_text_model"
9
+ },
10
+ "torch_dtype": "float32",
11
+ "transformers_version": "4.37.0.dev0",
12
+ "vision_config": {
13
+ "image_size": 512,
14
+ "model_type": "siglip_vision_model"
15
+ },
16
+ "max_position_embeddings": 64
17
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:11c613cde343cdd6c95c70ae50378dcd71c32ea80f1c940f06636fd79080be3e
3
+ size 441110496
special_tokens_map.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "eos_token": {
3
+ "content": "</s>",
4
+ "lstrip": true,
5
+ "normalized": false,
6
+ "rstrip": true,
7
+ "single_word": false
8
+ },
9
+ "pad_token": {
10
+ "content": "</s>",
11
+ "lstrip": true,
12
+ "normalized": false,
13
+ "rstrip": true,
14
+ "single_word": false
15
+ },
16
+ "unk_token": {
17
+ "content": "<unk>",
18
+ "lstrip": true,
19
+ "normalized": false,
20
+ "rstrip": true,
21
+ "single_word": false
22
+ }
23
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "1": {
4
+ "content": "</s>",
5
+ "lstrip": true,
6
+ "normalized": false,
7
+ "rstrip": true,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "2": {
12
+ "content": "<unk>",
13
+ "lstrip": true,
14
+ "normalized": false,
15
+ "rstrip": true,
16
+ "single_word": false,
17
+ "special": true
18
+ }
19
+ },
20
+ "additional_special_tokens": [],
21
+ "clean_up_tokenization_spaces": true,
22
+ "do_lower_case": true,
23
+ "eos_token": "</s>",
24
+ "model_input_names": [
25
+ "input_ids"
26
+ ],
27
+ "model_max_length": 64,
28
+ "pad_token": "</s>",
29
+ "processor_class": "SiglipProcessor",
30
+ "sp_model_kwargs": {},
31
+ "tokenizer_class": "SiglipTokenizer",
32
+ "unk_token": "<unk>"
33
+ }