timm
/

Image Feature Extraction
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
e269eb9
1 Parent(s): 7a03145
Files changed (4) hide show
  1. README.md +136 -0
  2. config.json +33 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_tag: timm
6
+ license: apache-2.0
7
+ ---
8
+ # Model card for eva02_base_patch14_224.mim_in22k
9
+
10
+ An EVA02 feature / representation model. Pretrained on ImageNet-22k with masked image modeling (using EVA-CLIP as a MIM teacher) by paper authors.
11
+
12
+ EVA-02 models are vision transformers with mean pooling, SwiGLU, Rotary Position Embeddings (ROPE), and extra LN in MLP (for Base & Large).
13
+
14
+ NOTE: `timm` checkpoints are float32 for consistency with other models. Original checkpoints are float16 or bfloat16 in some cases, see originals if that's preferred.
15
+
16
+
17
+ ## Model Details
18
+ - **Model Type:** Image classification / feature backbone
19
+ - **Model Stats:**
20
+ - Params (M): 85.8
21
+ - GMACs: 23.2
22
+ - Activations (M): 36.6
23
+ - Image size: 224 x 224
24
+ - **Papers:**
25
+ - EVA-02: A Visual Representation for Neon Genesis: https://arxiv.org/abs/2303.11331
26
+ - EVA-CLIP: Improved Training Techniques for CLIP at Scale: https://arxiv.org/abs/2303.15389
27
+ - **Original:**
28
+ - https://github.com/baaivision/EVA
29
+ - https://huggingface.co/Yuxin-CV/EVA-02
30
+ - **Pretrain Dataset:** ImageNet-22k
31
+
32
+ ## Model Usage
33
+ ### Image Classification
34
+ ```python
35
+ from urllib.request import urlopen
36
+ from PIL import Image
37
+ import timm
38
+
39
+ img = Image.open(urlopen(
40
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
41
+ ))
42
+
43
+ model = timm.create_model('eva02_base_patch14_224.mim_in22k', pretrained=True)
44
+ model = model.eval()
45
+
46
+ # get model specific transforms (normalization, resize)
47
+ data_config = timm.data.resolve_model_data_config(model)
48
+ transforms = timm.data.create_transform(**data_config, is_training=False)
49
+
50
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
51
+
52
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
53
+ ```
54
+
55
+ ### Image Embeddings
56
+ ```python
57
+ from urllib.request import urlopen
58
+ from PIL import Image
59
+ import timm
60
+
61
+ img = Image.open(urlopen(
62
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
63
+ ))
64
+
65
+ model = timm.create_model(
66
+ 'eva02_base_patch14_224.mim_in22k',
67
+ pretrained=True,
68
+ num_classes=0, # remove classifier nn.Linear
69
+ )
70
+ model = model.eval()
71
+
72
+ # get model specific transforms (normalization, resize)
73
+ data_config = timm.data.resolve_model_data_config(model)
74
+ transforms = timm.data.create_transform(**data_config, is_training=False)
75
+
76
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
77
+
78
+ # or equivalently (without needing to set num_classes=0)
79
+
80
+ output = model.forward_features(transforms(img).unsqueeze(0))
81
+ # output is unpooled, a (1, 257, 768) shaped tensor
82
+
83
+ output = model.forward_head(output, pre_logits=True)
84
+ # output is a (1, num_features) shaped tensor
85
+ ```
86
+
87
+ ## Model Comparison
88
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
89
+
90
+ |model |top1 |top5 |param_count|img_size|
91
+ |-----------------------------------------------|------|------|-----------|--------|
92
+ |eva02_large_patch14_448.mim_m38m_ft_in22k_in1k |90.054|99.042|305.08 |448 |
93
+ |eva02_large_patch14_448.mim_in22k_ft_in22k_in1k|89.946|99.01 |305.08 |448 |
94
+ |eva_giant_patch14_560.m30m_ft_in22k_in1k |89.792|98.992|1014.45 |560 |
95
+ |eva02_large_patch14_448.mim_in22k_ft_in1k |89.626|98.954|305.08 |448 |
96
+ |eva02_large_patch14_448.mim_m38m_ft_in1k |89.57 |98.918|305.08 |448 |
97
+ |eva_giant_patch14_336.m30m_ft_in22k_in1k |89.56 |98.956|1013.01 |336 |
98
+ |eva_giant_patch14_336.clip_ft_in1k |89.466|98.82 |1013.01 |336 |
99
+ |eva_large_patch14_336.in22k_ft_in22k_in1k |89.214|98.854|304.53 |336 |
100
+ |eva_giant_patch14_224.clip_ft_in1k |88.882|98.678|1012.56 |224 |
101
+ |eva02_base_patch14_448.mim_in22k_ft_in22k_in1k |88.692|98.722|87.12 |448 |
102
+ |eva_large_patch14_336.in22k_ft_in1k |88.652|98.722|304.53 |336 |
103
+ |eva_large_patch14_196.in22k_ft_in22k_in1k |88.592|98.656|304.14 |196 |
104
+ |eva02_base_patch14_448.mim_in22k_ft_in1k |88.23 |98.564|87.12 |448 |
105
+ |eva_large_patch14_196.in22k_ft_in1k |87.934|98.504|304.14 |196 |
106
+ |eva02_small_patch14_336.mim_in22k_ft_in1k |85.74 |97.614|22.13 |336 |
107
+ |eva02_tiny_patch14_336.mim_in22k_ft_in1k |80.658|95.524|5.76 |336 |
108
+
109
+ ## Citation
110
+ ```bibtex
111
+ @article{EVA02,
112
+ title={EVA-02: A Visual Representation for Neon Genesis},
113
+ author={Fang, Yuxin and Sun, Quan and Wang, Xinggang and Huang, Tiejun and Wang, Xinlong and Cao, Yue},
114
+ journal={arXiv preprint arXiv:2303.11331},
115
+ year={2023}
116
+ }
117
+ ```
118
+ ```bibtex
119
+ @article{EVA-CLIP,
120
+ title={EVA-02: A Visual Representation for Neon Genesis},
121
+ author={Sun, Quan and Fang, Yuxin and Wu, Ledell and Wang, Xinlong and Cao, Yue},
122
+ journal={arXiv preprint arXiv:2303.15389},
123
+ year={2023}
124
+ }
125
+ ```
126
+ ```bibtex
127
+ @misc{rw2019timm,
128
+ author = {Ross Wightman},
129
+ title = {PyTorch Image Models},
130
+ year = {2019},
131
+ publisher = {GitHub},
132
+ journal = {GitHub repository},
133
+ doi = {10.5281/zenodo.4414861},
134
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
135
+ }
136
+ ```
config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "eva02_base_patch14_224",
3
+ "num_classes": 0,
4
+ "num_features": 768,
5
+ "global_pool": "avg",
6
+ "pretrained_cfg": {
7
+ "tag": "mim_in22k",
8
+ "custom_load": false,
9
+ "input_size": [
10
+ 3,
11
+ 224,
12
+ 224
13
+ ],
14
+ "fixed_input_size": true,
15
+ "interpolation": "bicubic",
16
+ "crop_pct": 0.9,
17
+ "crop_mode": "center",
18
+ "mean": [
19
+ 0.48145466,
20
+ 0.4578275,
21
+ 0.40821073
22
+ ],
23
+ "std": [
24
+ 0.26862954,
25
+ 0.26130258,
26
+ 0.27577711
27
+ ],
28
+ "num_classes": 0,
29
+ "pool_size": null,
30
+ "first_conv": "patch_embed.proj",
31
+ "classifier": "head"
32
+ }
33
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a8f6984e7baf3d935b3c0d834e3fe1df5ebfe1d91f2e034041d1e0bf0afbed7b
3
+ size 343057022
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:65068e4594e95e55219046a19cfaba46d235eed91a529891a7ec72f6bbd1e2aa
3
+ size 343117429