Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- README.md +68 -3
- config.json +43 -0
- model.safetensors +3 -0
- preprocessor_config.json +29 -0
- sentencepiece.bpe.model +3 -0
- special_tokens_map.json +15 -0
- tokenizer.json +3 -0
- tokenizer_config.json +56 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,3 +1,68 @@
|
|
| 1 |
-
---
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
pipeline_tag: zero-shot-image-classification
|
| 4 |
+
license: cc-by-nc-4.0
|
| 5 |
+
tags:
|
| 6 |
+
- clip
|
| 7 |
+
- multilingual
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# Model Card for Distilled MetaCLIP 2 ViT-B/16 (worldwide)
|
| 11 |
+
|
| 12 |
+
Distilled MetaCLIP 2 (worldwide) was presented in [MetaCLIP 2: A Worldwide Scaling Recipe](https://huggingface.co/papers/2507.22062).
|
| 13 |
+
|
| 14 |
+
This checkpoint corresponds to "ViT-B-16-worldwide" of the [original implementation](https://github.com/facebookresearch/MetaCLIP).
|
| 15 |
+
|
| 16 |
+
## Install
|
| 17 |
+
|
| 18 |
+
First install the Transformers library (from source for now):
|
| 19 |
+
|
| 20 |
+
```bash
|
| 21 |
+
pip install -q git+https://github.com/huggingface/transformers.git
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
## Usage
|
| 25 |
+
|
| 26 |
+
Next you can use it like so:
|
| 27 |
+
|
| 28 |
+
```python
|
| 29 |
+
import torch
|
| 30 |
+
from transformers import pipeline
|
| 31 |
+
|
| 32 |
+
clip = pipeline(
|
| 33 |
+
task="zero-shot-image-classification",
|
| 34 |
+
model="facebook/metaclip-2-worldwide-b16",
|
| 35 |
+
torch_dtype=torch.bfloat16,
|
| 36 |
+
device=0
|
| 37 |
+
)
|
| 38 |
+
labels = ["a photo of a cat", "a photo of a dog", "a photo of a car"]
|
| 39 |
+
|
| 40 |
+
results = clip("http://images.cocodataset.org/val2017/000000039769.jpg", candidate_labels=labels)
|
| 41 |
+
print(results)
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
In case you want to perform pre- and postprocessing yourself, you can use the `AutoModel` API:
|
| 45 |
+
|
| 46 |
+
```python
|
| 47 |
+
import requests
|
| 48 |
+
import torch
|
| 49 |
+
from PIL import Image
|
| 50 |
+
from transformers import AutoProcessor, AutoModel
|
| 51 |
+
|
| 52 |
+
# note: make sure to verify that `AutoModel` is an instance of `MetaClip2Model`
|
| 53 |
+
model = AutoModel.from_pretrained("facebook/metaclip-2-worldwide-b16", torch_dtype=torch.bfloat16, attn_implementation="sdpa")
|
| 54 |
+
processor = AutoProcessor.from_pretrained("facebook/metaclip-2-worldwide-b16")
|
| 55 |
+
|
| 56 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
| 57 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 58 |
+
labels = ["a photo of a cat", "a photo of a dog", "a photo of a car"]
|
| 59 |
+
|
| 60 |
+
inputs = processor(text=labels, images=image, return_tensors="pt", padding=True)
|
| 61 |
+
|
| 62 |
+
outputs = model(**inputs)
|
| 63 |
+
logits_per_image = outputs.logits_per_image
|
| 64 |
+
probs = logits_per_image.softmax(dim=1)
|
| 65 |
+
most_likely_idx = probs.argmax(dim=1).item()
|
| 66 |
+
most_likely_label = labels[most_likely_idx]
|
| 67 |
+
print(f"Most likely label: {most_likely_label} with probability: {probs[0][most_likely_idx].item():.3f}")
|
| 68 |
+
```
|
config.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"MetaClip2Model"
|
| 4 |
+
],
|
| 5 |
+
"dtype": "float32",
|
| 6 |
+
"initializer_factor": 1.0,
|
| 7 |
+
"logit_scale_init_value": 2.6592,
|
| 8 |
+
"model_type": "metaclip_2",
|
| 9 |
+
"projection_dim": 512,
|
| 10 |
+
"text_config": {
|
| 11 |
+
"attention_dropout": 0.0,
|
| 12 |
+
"eos_token_id": 2,
|
| 13 |
+
"hidden_act": "gelu",
|
| 14 |
+
"hidden_size": 512,
|
| 15 |
+
"initializer_factor": 1.0,
|
| 16 |
+
"initializer_range": 0.02,
|
| 17 |
+
"intermediate_size": 2048,
|
| 18 |
+
"layer_norm_eps": 1e-05,
|
| 19 |
+
"max_position_embeddings": 77,
|
| 20 |
+
"model_type": "metaclip_2_text_model",
|
| 21 |
+
"num_attention_heads": 8,
|
| 22 |
+
"num_hidden_layers": 12,
|
| 23 |
+
"projection_dim": 512,
|
| 24 |
+
"vocab_size": 901629
|
| 25 |
+
},
|
| 26 |
+
"transformers_version": "4.57.1",
|
| 27 |
+
"vision_config": {
|
| 28 |
+
"attention_dropout": 0.0,
|
| 29 |
+
"hidden_act": "gelu",
|
| 30 |
+
"hidden_size": 768,
|
| 31 |
+
"image_size": 224,
|
| 32 |
+
"initializer_factor": 1.0,
|
| 33 |
+
"initializer_range": 0.02,
|
| 34 |
+
"intermediate_size": 3072,
|
| 35 |
+
"layer_norm_eps": 1e-05,
|
| 36 |
+
"model_type": "metaclip_2_vision_model",
|
| 37 |
+
"num_attention_heads": 12,
|
| 38 |
+
"num_channels": 3,
|
| 39 |
+
"num_hidden_layers": 12,
|
| 40 |
+
"patch_size": 16,
|
| 41 |
+
"projection_dim": 512
|
| 42 |
+
}
|
| 43 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5ba4b60a28a3f563b0d2cf1f3de14298b6592ca9cbe53b2694936ff8bb7b5eba
|
| 3 |
+
size 2343879772
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"crop_size": {
|
| 3 |
+
"height": 224,
|
| 4 |
+
"width": 224
|
| 5 |
+
},
|
| 6 |
+
"do_center_crop": true,
|
| 7 |
+
"do_convert_rgb": true,
|
| 8 |
+
"do_normalize": true,
|
| 9 |
+
"do_rescale": true,
|
| 10 |
+
"do_resize": true,
|
| 11 |
+
"image_mean": [
|
| 12 |
+
0.48145466,
|
| 13 |
+
0.4578275,
|
| 14 |
+
0.40821073
|
| 15 |
+
],
|
| 16 |
+
"image_processor_type": "CLIPImageProcessor",
|
| 17 |
+
"image_std": [
|
| 18 |
+
0.26862954,
|
| 19 |
+
0.26130258,
|
| 20 |
+
0.27577711
|
| 21 |
+
],
|
| 22 |
+
"processor_class": "CLIPProcessor",
|
| 23 |
+
"resample": 3,
|
| 24 |
+
"rescale_factor": 0.00392156862745098,
|
| 25 |
+
"size": {
|
| 26 |
+
"height": 224,
|
| 27 |
+
"width": 224
|
| 28 |
+
}
|
| 29 |
+
}
|
sentencepiece.bpe.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dbee9f6b1c2cba29b335e70d6088eea943c7d5ae55ac7dd17174760bf758e309
|
| 3 |
+
size 18241665
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": "<s>",
|
| 3 |
+
"cls_token": "<s>",
|
| 4 |
+
"eos_token": "</s>",
|
| 5 |
+
"mask_token": {
|
| 6 |
+
"content": "<mask>",
|
| 7 |
+
"lstrip": true,
|
| 8 |
+
"normalized": false,
|
| 9 |
+
"rstrip": false,
|
| 10 |
+
"single_word": false
|
| 11 |
+
},
|
| 12 |
+
"pad_token": "<pad>",
|
| 13 |
+
"sep_token": "</s>",
|
| 14 |
+
"unk_token": "<unk>"
|
| 15 |
+
}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f9b777521f1113c9a64cdbd2bccbc890c17d7b4d451777cd67839cd45760da83
|
| 3 |
+
size 61333880
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "<s>",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"1": {
|
| 12 |
+
"content": "<pad>",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"2": {
|
| 20 |
+
"content": "</s>",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"3": {
|
| 28 |
+
"content": "<unk>",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": false,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"901628": {
|
| 36 |
+
"content": "<mask>",
|
| 37 |
+
"lstrip": true,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"bos_token": "<s>",
|
| 45 |
+
"clean_up_tokenization_spaces": false,
|
| 46 |
+
"cls_token": "<s>",
|
| 47 |
+
"eos_token": "</s>",
|
| 48 |
+
"extra_special_tokens": {},
|
| 49 |
+
"mask_token": "<mask>",
|
| 50 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 51 |
+
"pad_token": "<pad>",
|
| 52 |
+
"processor_class": "CLIPProcessor",
|
| 53 |
+
"sep_token": "</s>",
|
| 54 |
+
"tokenizer_class": "XLMRobertaTokenizer",
|
| 55 |
+
"unk_token": "<unk>"
|
| 56 |
+
}
|