Zero-Shot Image Classification
Transformers
Safetensors
siglip
vision
m-toman commited on
Commit
e822b89
·
verified ·
1 Parent(s): 4036979

Upload vision model tensors

Browse files
Files changed (4) hide show
  1. README.md +112 -0
  2. config.json +26 -0
  3. model.safetensors +3 -0
  4. preprocessor_config.json +24 -0
README.md ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - vision
5
+ widget:
6
+ - src: >-
7
+ https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg
8
+ candidate_labels: bee in the sky, bee on the flower
9
+ example_title: Bee
10
+ library_name: transformers
11
+ pipeline_tag: zero-shot-image-classification
12
+ ---
13
+
14
+ # Vision tower of `google/siglip2-large-patch16-384`
15
+
16
+ > **Note:** This is a stripped-down copy of [`google/siglip2-large-patch16-384`](https://huggingface.co/google/siglip2-large-patch16-384) containing only the **vision tower**. It encodes images / video frames into the shared embedding space and is meant to be loaded on its own at **indexing** time, separately from the other tower. Splitting the towers lets you load only the half you need, saving memory and load time.
17
+ >
18
+ > The text tower (used at retrieval time) lives in [`Veritone/siglip2-large-patch16-384-text`](https://huggingface.co/Veritone/siglip2-large-patch16-384-text).
19
+
20
+ ---
21
+
22
+ ## Original model card
23
+
24
+ # SigLIP 2 Large
25
+
26
+ [SigLIP 2](https://huggingface.co/papers/2502.14786) extends the pretraining objective of
27
+ [SigLIP](https://huggingface.co/papers/2303.15343) with prior, independently developed techniques
28
+ into a unified recipe, for improved semantic understanding, localization, and dense features.
29
+
30
+ ## Intended uses
31
+
32
+ You can use the raw model for tasks like zero-shot image classification and
33
+ image-text retrieval, or as a vision encoder for VLMs (and other vision tasks).
34
+
35
+ Here is how to use this model to perform zero-shot image classification:
36
+
37
+ ```python
38
+ from transformers import pipeline
39
+
40
+ # load pipeline
41
+ ckpt = "google/siglip2-large-patch16-384"
42
+ image_classifier = pipeline(model=ckpt, task="zero-shot-image-classification")
43
+
44
+ # load image and candidate labels
45
+ url = "http://images.cocodataset.org/val2017/000000039769.jpg"
46
+ candidate_labels = ["2 cats", "a plane", "a remote"]
47
+
48
+ # run inference
49
+ outputs = image_classifier(image, candidate_labels)
50
+ print(outputs)
51
+ ```
52
+
53
+ You can encode an image using the Vision Tower like so:
54
+
55
+ ```python
56
+ import torch
57
+ from transformers import AutoModel, AutoProcessor
58
+ from transformers.image_utils import load_image
59
+
60
+ # load the model and processor
61
+ ckpt = "google/siglip2-large-patch16-384"
62
+ model = AutoModel.from_pretrained(ckpt, device_map="auto").eval()
63
+ processor = AutoProcessor.from_pretrained(ckpt)
64
+
65
+ # load the image
66
+ image = load_image("https://huggingface.co/datasets/merve/coco/resolve/main/val2017/000000000285.jpg")
67
+ inputs = processor(images=[image], return_tensors="pt").to(model.device)
68
+
69
+ # run infernece
70
+ with torch.no_grad():
71
+ image_embeddings = model.get_image_features(**inputs)
72
+
73
+ print(image_embeddings.shape)
74
+ ```
75
+
76
+ For more code examples, we refer to the [siglip documentation](https://huggingface.co/transformers/main/model_doc/siglip.html#).
77
+
78
+ ## Training procedure
79
+
80
+ SigLIP 2 adds some clever training objectives on top of SigLIP:
81
+
82
+ 1. Decoder loss
83
+ 2. Global-local and masked prediction loss
84
+ 3. Aspect ratio and resolution adaptibility
85
+
86
+ ### Training data
87
+
88
+ SigLIP 2 is pre-trained on the WebLI dataset [(Chen et al., 2023)](https://arxiv.org/abs/2209.06794).
89
+
90
+ ### Compute
91
+
92
+ The model was trained on up to 2048 TPU-v5e chips.
93
+
94
+ ## Evaluation results
95
+
96
+ Evaluation of SigLIP 2 is shown below (taken from the paper).
97
+
98
+ ![Evaluation Table](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/blog/sg2-blog/eval_table.png)
99
+
100
+ ### BibTeX entry and citation info
101
+
102
+ ```bibtex
103
+ @misc{tschannen2025siglip2multilingualvisionlanguage,
104
+ title={SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Features},
105
+ author={Michael Tschannen and Alexey Gritsenko and Xiao Wang and Muhammad Ferjad Naeem and Ibrahim Alabdulmohsin and Nikhil Parthasarathy and Talfan Evans and Lucas Beyer and Ye Xia and Basil Mustafa and Olivier Hénaff and Jeremiah Harmsen and Andreas Steiner and Xiaohua Zhai},
106
+ year={2025},
107
+ eprint={2502.14786},
108
+ archivePrefix={arXiv},
109
+ primaryClass={cs.CV},
110
+ url={https://arxiv.org/abs/2502.14786},
111
+ }
112
+ ```
config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "initializer_factor": 1.0,
3
+ "model_type": "siglip",
4
+ "text_config": {
5
+ "hidden_size": 1024,
6
+ "intermediate_size": 4096,
7
+ "model_type": "siglip_text_model",
8
+ "num_attention_heads": 16,
9
+ "num_hidden_layers": 24,
10
+ "projection_size": 1024,
11
+ "vocab_size": 256000
12
+ },
13
+ "transformers_version": "4.49.0.dev0",
14
+ "vision_config": {
15
+ "hidden_size": 1024,
16
+ "image_size": 384,
17
+ "intermediate_size": 4096,
18
+ "model_type": "siglip_vision_model",
19
+ "num_attention_heads": 16,
20
+ "num_hidden_layers": 24
21
+ },
22
+ "architectures": [
23
+ "SiglipModel"
24
+ ],
25
+ "max_position_embeddings": 64
26
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e459aa22d360b6fe9655e797c39a2b0fbeed0a82d860baedb0a544bb73d985e
3
+ size 1265184520
preprocessor_config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_convert_rgb": null,
3
+ "do_normalize": true,
4
+ "do_rescale": true,
5
+ "do_resize": true,
6
+ "image_mean": [
7
+ 0.5,
8
+ 0.5,
9
+ 0.5
10
+ ],
11
+ "image_processor_type": "SiglipImageProcessor",
12
+ "image_std": [
13
+ 0.5,
14
+ 0.5,
15
+ 0.5
16
+ ],
17
+ "processor_class": "SiglipProcessor",
18
+ "resample": 2,
19
+ "rescale_factor": 0.00392156862745098,
20
+ "size": {
21
+ "height": 384,
22
+ "width": 384
23
+ }
24
+ }