Zhijian Liu
commited on
Commit
·
5d16503
1
Parent(s):
a196bf5
Add `paligemma-siglip-so400m-patch14-448`
Browse files- README.md +112 -0
- config.json +29 -0
- model.safetensors +3 -0
- preprocessor_config.json +23 -0
- special_tokens_map.json +23 -0
- spiece.model +3 -0
- tokenizer_config.json +33 -0
README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# SigLIP (shape-optimized model)
|
| 12 |
+
|
| 13 |
+
SigLIP model pre-trained on WebLi at resolution 384x384. 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).
|
| 14 |
+
|
| 15 |
+
This model has the SoViT-400m architecture, which is the shape-optimized version as presented in [Getting ViT in Shape: Scaling Laws for Compute-Optimal Model Design](https://arxiv.org/abs/2305.13035) by Alabdulmohsin et al.
|
| 16 |
+
|
| 17 |
+
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.
|
| 18 |
+
|
| 19 |
+
## Model description
|
| 20 |
+
|
| 21 |
+
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.
|
| 22 |
+
|
| 23 |
+
A TLDR of SigLIP by one of the authors can be found [here](https://twitter.com/giffmana/status/1692641733459267713).
|
| 24 |
+
|
| 25 |
+
## Intended uses & limitations
|
| 26 |
+
|
| 27 |
+
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
|
| 28 |
+
other versions on a task that interests you.
|
| 29 |
+
|
| 30 |
+
### How to use
|
| 31 |
+
|
| 32 |
+
Here is how to use this model to perform zero-shot image classification:
|
| 33 |
+
|
| 34 |
+
```python
|
| 35 |
+
from PIL import Image
|
| 36 |
+
import requests
|
| 37 |
+
from transformers import AutoProcessor, AutoModel
|
| 38 |
+
import torch
|
| 39 |
+
|
| 40 |
+
model = AutoModel.from_pretrained("google/siglip-so400m-patch14-384")
|
| 41 |
+
processor = AutoProcessor.from_pretrained("google/siglip-so400m-patch14-384")
|
| 42 |
+
|
| 43 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
| 44 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 45 |
+
|
| 46 |
+
texts = ["a photo of 2 cats", "a photo of 2 dogs"]
|
| 47 |
+
inputs = processor(text=texts, images=image, padding="max_length", return_tensors="pt")
|
| 48 |
+
|
| 49 |
+
with torch.no_grad():
|
| 50 |
+
outputs = model(**inputs)
|
| 51 |
+
|
| 52 |
+
logits_per_image = outputs.logits_per_image
|
| 53 |
+
probs = torch.sigmoid(logits_per_image) # these are the probabilities
|
| 54 |
+
print(f"{probs[0][0]:.1%} that image 0 is '{texts[0]}'")
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
Alternatively, one can leverage the pipeline API which abstracts away the complexity for the user:
|
| 58 |
+
|
| 59 |
+
```python
|
| 60 |
+
from transformers import pipeline
|
| 61 |
+
from PIL import Image
|
| 62 |
+
import requests
|
| 63 |
+
|
| 64 |
+
# load pipe
|
| 65 |
+
image_classifier = pipeline(task="zero-shot-image-classification", model="google/siglip-so400m-patch14-384")
|
| 66 |
+
|
| 67 |
+
# load image
|
| 68 |
+
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
| 69 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 70 |
+
|
| 71 |
+
# inference
|
| 72 |
+
outputs = image_classifier(image, candidate_labels=["2 cats", "a plane", "a remote"])
|
| 73 |
+
outputs = [{"score": round(output["score"], 4), "label": output["label"] } for output in outputs]
|
| 74 |
+
print(outputs)
|
| 75 |
+
```
|
| 76 |
+
For more code examples, we refer to the [documentation](https://huggingface.co/transformers/main/model_doc/siglip.html#).
|
| 77 |
+
|
| 78 |
+
## Training procedure
|
| 79 |
+
|
| 80 |
+
### Training data
|
| 81 |
+
|
| 82 |
+
SigLIP is pre-trained on the WebLI dataset [(Chen et al., 2023)](https://arxiv.org/abs/2209.06794).
|
| 83 |
+
|
| 84 |
+
### Preprocessing
|
| 85 |
+
|
| 86 |
+
Images are resized/rescaled to the same resolution (384x384) and normalized across the RGB channels with mean (0.5, 0.5, 0.5) and standard deviation (0.5, 0.5, 0.5).
|
| 87 |
+
|
| 88 |
+
Texts are tokenized and padded to the same length (64 tokens).
|
| 89 |
+
|
| 90 |
+
### Compute
|
| 91 |
+
|
| 92 |
+
The model was trained on 16 TPU-v4 chips for three days.
|
| 93 |
+
|
| 94 |
+
## Evaluation results
|
| 95 |
+
|
| 96 |
+
Evaluation of SigLIP compared to CLIP is shown below (taken from the paper).
|
| 97 |
+
|
| 98 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/siglip_table.jpeg"
|
| 99 |
+
alt="drawing" width="600"/>
|
| 100 |
+
|
| 101 |
+
### BibTeX entry and citation info
|
| 102 |
+
|
| 103 |
+
```bibtex
|
| 104 |
+
@misc{zhai2023sigmoid,
|
| 105 |
+
title={Sigmoid Loss for Language Image Pre-Training},
|
| 106 |
+
author={Xiaohua Zhai and Basil Mustafa and Alexander Kolesnikov and Lucas Beyer},
|
| 107 |
+
year={2023},
|
| 108 |
+
eprint={2303.15343},
|
| 109 |
+
archivePrefix={arXiv},
|
| 110 |
+
primaryClass={cs.CV}
|
| 111 |
+
}
|
| 112 |
+
```
|
config.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"SiglipModel"
|
| 4 |
+
],
|
| 5 |
+
"initializer_factor": 1.0,
|
| 6 |
+
"model_type": "siglip",
|
| 7 |
+
"text_config": {
|
| 8 |
+
"hidden_size": 1152,
|
| 9 |
+
"intermediate_size": 4304,
|
| 10 |
+
"model_type": "siglip_text_model",
|
| 11 |
+
"num_attention_heads": 16,
|
| 12 |
+
"num_hidden_layers": 27
|
| 13 |
+
},
|
| 14 |
+
"torch_dtype": "float32",
|
| 15 |
+
"transformers_version": "4.37.0.dev0",
|
| 16 |
+
"vision_config": {
|
| 17 |
+
"hidden_size": 1152,
|
| 18 |
+
"image_size": 448,
|
| 19 |
+
"intermediate_size": 4304,
|
| 20 |
+
"model_type": "siglip_vision_model",
|
| 21 |
+
"num_attention_heads": 16,
|
| 22 |
+
"num_hidden_layers": 27,
|
| 23 |
+
"num_image_tokens": 256,
|
| 24 |
+
"patch_size": 14,
|
| 25 |
+
"projection_dim": 2048,
|
| 26 |
+
"projector_hidden_act": "gelu_fast",
|
| 27 |
+
"vision_use_head": false
|
| 28 |
+
}
|
| 29 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7ee9ab6ae78e0e3cfc72c4839013d710f3e8807f612f91dfa8877b8d60d08d3f
|
| 3 |
+
size 3513309984
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"do_normalize": true,
|
| 3 |
+
"do_rescale": true,
|
| 4 |
+
"do_resize": true,
|
| 5 |
+
"image_mean": [
|
| 6 |
+
0.5,
|
| 7 |
+
0.5,
|
| 8 |
+
0.5
|
| 9 |
+
],
|
| 10 |
+
"image_processor_type": "SiglipImageProcessor",
|
| 11 |
+
"image_std": [
|
| 12 |
+
0.5,
|
| 13 |
+
0.5,
|
| 14 |
+
0.5
|
| 15 |
+
],
|
| 16 |
+
"processor_class": "SiglipProcessor",
|
| 17 |
+
"resample": 3,
|
| 18 |
+
"rescale_factor": 0.00392156862745098,
|
| 19 |
+
"size": {
|
| 20 |
+
"height": 448,
|
| 21 |
+
"width": 448
|
| 22 |
+
}
|
| 23 |
+
}
|
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 |
+
}
|
spiece.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1e5036bed065526c3c212dfbe288752391797c4bb1a284aa18c9a0b23fcaf8ec
|
| 3 |
+
size 798330
|
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 |
+
}
|