RuteNL commited on
Commit
55f26d5
·
verified ·
1 Parent(s): 40ed4f7

Upload 11 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ 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
+ text.onnx.data filter=lfs diff=lfs merge=lfs -text
37
+ visual.onnx.data filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,3 +1,80 @@
 
 
 
 
1
  ---
 
 
 
 
 
 
2
  license: apple-amlr
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # open_clip_rs ONNX export of timm/MobileCLIP2-S2-OpenCLIP
2
+
3
+ This model is an export of [timm/MobileCLIP2-S2-OpenCLIP](https://huggingface.co/timm/MobileCLIP2-S2-OpenCLIP). It is meant to be used with the [`open_clip_inference`](https://crates.io/crates/open_clip_inference) rust crate.
4
+
5
  ---
6
+ ---
7
+ tags:
8
+ - clip
9
+ - mobileclip2
10
+ library_name: open_clip
11
+ pipeline_tag: zero-shot-image-classification
12
  license: apple-amlr
13
  ---
14
+ # Model card for MobileCLIP2-S2-OpenCLIP
15
+ These weights and model card are adapted from the original Apple model at https://huggingface.co/apple/MobileCLIP2-S2. This version uses canonical OpenCLIP configs and weight naming.
16
+
17
+ MobileCLIP2 was introduced in [MobileCLIP2: Improving Multi-Modal Reinforced Training](http://arxiv.org/abs/2508.20691) (TMLR August 2025 <mark>Featured</mark>), by Fartash Faghri, Pavan Kumar Anasosalu Vasu, Cem Koc, Vaishaal Shankar, Alexander T Toshev, Oncel Tuzel, Hadi Pouransari.
18
+
19
+ This repository contains the **MobileCLIP2-S2** checkpoint.
20
+
21
+ ### Highlights
22
+
23
+ * `MobileCLIP2-S4` matches the accuracy of SigLIP-SO400M/14 with 2x fewer parameters and surpasses DFN ViT-L/14 at 2.5x lower latency measured on iPhone12 Pro Max.
24
+ * `MobileCLIP-S3/S4` are our new architectures trained on MobileCLIP’s training dataset, DataCompDR-1B (dashed lines).
25
+ * Our smallest variant `MobileCLIP-S0` obtains similar zero-shot performance as [OpenAI](https://arxiv.org/abs/2103.00020)'s ViT-B/16 model while being 4.8x faster and 2.8x smaller.
26
+ * `MobileCLIP-S2` obtains better avg zero-shot performance than [SigLIP](https://arxiv.org/abs/2303.15343)'s ViT-B/16 model while being 2.3x faster and 2.1x smaller, and trained with 3x less seen samples.
27
+ * `MobileCLIP-B (LT)` attains zero-shot ImageNet performance of **77.2%** which is significantly better than recent works like [DFN](https://arxiv.org/abs/2309.17425) and [SigLIP](https://arxiv.org/abs/2303.15343) with similar architectures or even [OpenAI's ViT-L/14@336](https://arxiv.org/abs/2103.00020).
28
+
29
+
30
+ ## Checkpoints and Results (Original Apple links)
31
+
32
+ | Model | # Seen <BR>Samples (B) | # Params (M) <BR> (img + txt) | Latency (ms) <BR> (img + txt) | IN-1k Zero-Shot <BR> Top-1 Acc. (%) | Avg. Perf. (%) <BR> on 38 datasets |
33
+ |:----------------------------------------------------------|:----------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------------:|:----------------------------------:|
34
+ | [MobileCLIP2-S0](https://hf.co/apple/MobileCLIP2-S0) | 13 | 11.4 + 42.4 | 1.5 + 1.6 | 71.5 | 59.7 |
35
+ | [MobileCLIP2-S2](https://hf.co/apple/MobileCLIP2-S2) | 13 | 35.7 + 63.4 | 3.6 + 3.3 | 77.2 | 64.1 |
36
+ | [MobileCLIP2-B](https://hf.co/apple/MobileCLIP2-B) | 13 | 86.3 + 63.4 | 10.4 + 3.3 | 79.4 | 65.8 |
37
+ | [MobileCLIP2-S3](https://hf.co/apple/MobileCLIP2-S3) | 13 | 125.1 + 123.6 | 8.0 + 6.6 | 80.7 | 66.8 |
38
+ | [MobileCLIP2-L/14](https://hf.co/apple/MobileCLIP2-L-14) | 13 | 304.3 + 123.6 | 57.9 + 6.6 | 81.9 | 67.8 |
39
+ | [MobileCLIP2-S4](https://hf.co/apple/MobileCLIP2-S4) | 13 | 321.6 + 123.6 | 19.6 + 6.6 | 81.9 | 67.5 |
40
+ | [MobileCLIP-S0](https://hf.co/apple/MobileCLIP-S0) | 13 | 11.4 + 42.4 | 1.5 + 1.6 | 67.8 | 58.1 |
41
+ | [MobileCLIP-S1](https://hf.co/apple/MobileCLIP-S1) | 13 | 21.5 + 63.4 | 2.5 + 3.3 | 72.6 | 61.3 |
42
+ | [MobileCLIP-S2](https://hf.co/apple/MobileCLIP-S2) | 13 | 35.7 + 63.4 | 3.6 + 3.3 | 74.4 | 63.7 |
43
+ | [MobileCLIP-B](https://hf.co/apple/MobileCLIP-B) | 13 | 86.3 + 63.4 | 10.4 + 3.3 | 76.8 | 65.2 |
44
+ | [MobileCLIP-B (LT)](https://hf.co/apple/MobileCLIP-B-LT) | 36 | 86.3 + 63.4 | 10.4 + 3.3 | 77.2 | 65.8 |
45
+ | [MobileCLIP-S3](https://hf.co/apple/MobileCLIP-S3) | 13 | 125.1 + 123.6 | 8.0 + 6.6 | 78.3 | 66.3 |
46
+ | [MobileCLIP-L/14](https://hf.co/apple/MobileCLIP-L-14) | 13 | 304.3 + 123.6 | 57.9 + 6.6 | 79.5 | 66.9 |
47
+ | [MobileCLIP-S4](https://hf.co/apple/MobileCLIP-S4) | 13 | 321.6 + 123.6 | 19.6 + 6.6 | 79.4 | 68.1 |
48
+
49
+
50
+ ## How to Use
51
+
52
+ ```py
53
+ import torch
54
+ import open_clip
55
+ from PIL import Image
56
+ from urllib.request import urlopen
57
+ from timm.utils import reparameterize_model
58
+
59
+ model, _, preprocess = open_clip.create_model_and_transforms('MobileCLIP2-S0', pretrained='dfndr2b')
60
+ model.eval()
61
+ tokenizer = open_clip.get_tokenizer('MobileCLIP2-S0')
62
+
63
+ # For inference/model exporting purposes, optionally reparameterize for better performance
64
+ model = reparameterize_model(model)
65
+
66
+ image = Image.open(urlopen(
67
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
68
+ ))
69
+ image = preprocess(image).unsqueeze(0)
70
+ text = tokenizer(["a diagram", "a dog", "a cat", "a doughnut"])
71
+
72
+ with torch.no_grad(), torch.amp.autocast(image.device.type):
73
+ image_features = model.encode_image(image)
74
+ text_features = model.encode_text(text)
75
+ image_features /= image_features.norm(dim=-1, keepdim=True)
76
+ text_features /= text_features.norm(dim=-1, keepdim=True)
77
+ text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
78
+
79
+ print("Label probs:", text_probs)
80
+ ```
model_config.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "logit_scale": 55.869911193847656,
3
+ "logit_bias": 0.0,
4
+ "activation_function": "softmax",
5
+ "tokenizer_needs_lowercase": false,
6
+ "pad_id": 0,
7
+ "vocab_size": 49408
8
+ }
open_clip_config.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_cfg": {
3
+ "embed_dim": 512,
4
+ "vision_cfg": {
5
+ "timm_model_name": "fastvit_mci2",
6
+ "timm_model_pretrained": false,
7
+ "timm_pool": "avg",
8
+ "timm_proj": null,
9
+ "timm_drop": 0.0,
10
+ "timm_drop_path": 0.0,
11
+ "image_size": 256
12
+ },
13
+ "text_cfg": {
14
+ "context_length": 77,
15
+ "vocab_size": 49408,
16
+ "width": 512,
17
+ "heads": 8,
18
+ "layers": 12,
19
+ "no_causal_mask": true,
20
+ "hf_tokenizer_name": "timm/MobileCLIP2-S2-OpenCLIP"
21
+ },
22
+ "custom_text": true
23
+ },
24
+ "preprocess_cfg": {
25
+ "mean": [
26
+ 0.0,
27
+ 0.0,
28
+ 0.0
29
+ ],
30
+ "std": [
31
+ 1.0,
32
+ 1.0,
33
+ 1.0
34
+ ],
35
+ "interpolation": "bilinear",
36
+ "resize_mode": "shortest"
37
+ }
38
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<|startoftext|>",
4
+ "lstrip": false,
5
+ "normalized": true,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<|endoftext|>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "<|endoftext|>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "<|endoftext|>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
text.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c7046e2a3c4078fd0b10865f3063bfa8e89c0808de3bd2fcaf89ba0d0a2fe90f
3
+ size 1517435
text.onnx.data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b0e6225b1a9e8b15b1abedcc430ebb369c9695831c9b0922acf9e83906e03e47
3
+ size 253755392
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "49406": {
5
+ "content": "<|startoftext|>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "49407": {
13
+ "content": "<|endoftext|>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ }
20
+ },
21
+ "bos_token": "<|startoftext|>",
22
+ "clean_up_tokenization_spaces": false,
23
+ "do_lower_case": true,
24
+ "eos_token": "<|endoftext|>",
25
+ "errors": "replace",
26
+ "extra_special_tokens": {},
27
+ "model_max_length": 77,
28
+ "pad_token": "<|endoftext|>",
29
+ "tokenizer_class": "CLIPTokenizer",
30
+ "unk_token": "<|endoftext|>"
31
+ }
visual.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8bb691c4085f8767c8237e324816a430f8264b5c2d4542ec2d9f88d701faa823
3
+ size 2310022
visual.onnx.data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:365f1b95476a0852aaf5b136432383ff9405eedc3deb5347c2b8398a3838f50c
3
+ size 143589376