voidism commited on
Commit
a71dd14
·
verified ·
1 Parent(s): 7d95789

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -1,3 +1,68 @@
1
- ---
2
- license: cc-by-nc-4.0
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-S/16 (mT5 Tokenizer) (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-S-16-mT5-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-mt5-worldwide-s16",
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-mt5-worldwide-s16", torch_dtype=torch.bfloat16, attn_implementation="sdpa")
54
+ processor = AutoProcessor.from_pretrained("facebook/metaclip-2-mt5-worldwide-s16")
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": 384,
10
+ "text_config": {
11
+ "attention_dropout": 0.0,
12
+ "eos_token_id": 1,
13
+ "hidden_act": "gelu",
14
+ "hidden_size": 384,
15
+ "initializer_factor": 1.0,
16
+ "initializer_range": 0.02,
17
+ "intermediate_size": 1536,
18
+ "layer_norm_eps": 1e-05,
19
+ "max_position_embeddings": 77,
20
+ "model_type": "metaclip_2_text_model",
21
+ "num_attention_heads": 6,
22
+ "num_hidden_layers": 12,
23
+ "projection_dim": 384,
24
+ "vocab_size": 250000
25
+ },
26
+ "transformers_version": "4.57.1",
27
+ "vision_config": {
28
+ "attention_dropout": 0.0,
29
+ "hidden_act": "gelu",
30
+ "hidden_size": 384,
31
+ "image_size": 224,
32
+ "initializer_factor": 1.0,
33
+ "initializer_range": 0.02,
34
+ "intermediate_size": 1536,
35
+ "layer_norm_eps": 1e-05,
36
+ "model_type": "metaclip_2_vision_model",
37
+ "num_attention_heads": 6,
38
+ "num_channels": 3,
39
+ "num_hidden_layers": 12,
40
+ "patch_size": 16,
41
+ "projection_dim": 384
42
+ }
43
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8c3d2c36fddc03e0fd5576d09195f97d85d293acfc985600b5088fc9fd83101d
3
+ size 557186884
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
+ }
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:ef78f86560d809067d12bac6c09f19a462cb3af3f54d2b8acbba26e1433125d6
3
+ size 4309802
tokenizer_config.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "extra_special_tokens": {},
25
+ "model_input_names": [
26
+ "input_ids"
27
+ ],
28
+ "model_max_length": 64,
29
+ "pad_token": "</s>",
30
+ "processor_class": "CLIPProcessor",
31
+ "sp_model_kwargs": {},
32
+ "tokenizer_class": "SiglipTokenizer",
33
+ "unk_token": "<unk>"
34
+ }