timm
/

Image Feature Extraction
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
e3f8ef9
1 Parent(s): 2c993e2
Files changed (4) hide show
  1. README.md +104 -0
  2. config.json +33 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - timm
4
+ - image-classification
5
+ library_name: timm
6
+ license: apache-2.0
7
+ datasets:
8
+ - imagenet-21k
9
+ ---
10
+ # Model card for vit_large_patch16_224.orig_in21k
11
+
12
+ A Vision Transformer (ViT) image classification model. Pretrained on ImageNet-21k in JAX by paper authors, ported to PyTorch by Ross Wightman. This model does not have a classification head, useful for features and fine-tune only.
13
+
14
+
15
+ ## Model Details
16
+ - **Model Type:** Image classification / feature backbone
17
+ - **Model Stats:**
18
+ - Params (M): 303.3
19
+ - GMACs: 59.7
20
+ - Activations (M): 43.8
21
+ - Image size: 224 x 224
22
+ - **Papers:**
23
+ - An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale: https://arxiv.org/abs/2010.11929v2
24
+ - **Dataset:** ImageNet-21k
25
+ - **Original:** https://github.com/google-research/vision_transformer
26
+
27
+ ## Model Usage
28
+ ### Image Classification
29
+ ```python
30
+ from urllib.request import urlopen
31
+ from PIL import Image
32
+ import timm
33
+
34
+ img = Image.open(urlopen(
35
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
36
+ ))
37
+
38
+ model = timm.create_model('vit_large_patch16_224.orig_in21k', pretrained=True)
39
+ model = model.eval()
40
+
41
+ # get model specific transforms (normalization, resize)
42
+ data_config = timm.data.resolve_model_data_config(model)
43
+ transforms = timm.data.create_transform(**data_config, is_training=False)
44
+
45
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
46
+
47
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
48
+ ```
49
+
50
+ ### Image Embeddings
51
+ ```python
52
+ from urllib.request import urlopen
53
+ from PIL import Image
54
+ import timm
55
+
56
+ img = Image.open(urlopen(
57
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
58
+ ))
59
+
60
+ model = timm.create_model(
61
+ 'vit_large_patch16_224.orig_in21k',
62
+ pretrained=True,
63
+ num_classes=0, # remove classifier nn.Linear
64
+ )
65
+ model = model.eval()
66
+
67
+ # get model specific transforms (normalization, resize)
68
+ data_config = timm.data.resolve_model_data_config(model)
69
+ transforms = timm.data.create_transform(**data_config, is_training=False)
70
+
71
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
72
+
73
+ # or equivalently (without needing to set num_classes=0)
74
+
75
+ output = model.forward_features(transforms(img).unsqueeze(0))
76
+ # output is unpooled, a (1, 197, 1024) shaped tensor
77
+
78
+ output = model.forward_head(output, pre_logits=True)
79
+ # output is a (1, num_features) shaped tensor
80
+ ```
81
+
82
+ ## Model Comparison
83
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
84
+
85
+ ## Citation
86
+ ```bibtex
87
+ @article{dosovitskiy2020vit,
88
+ title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
89
+ author={Dosovitskiy, Alexey and Beyer, Lucas and Kolesnikov, Alexander and Weissenborn, Dirk and Zhai, Xiaohua and Unterthiner, Thomas and Dehghani, Mostafa and Minderer, Matthias and Heigold, Georg and Gelly, Sylvain and Uszkoreit, Jakob and Houlsby, Neil},
90
+ journal={ICLR},
91
+ year={2021}
92
+ }
93
+ ```
94
+ ```bibtex
95
+ @misc{rw2019timm,
96
+ author = {Ross Wightman},
97
+ title = {PyTorch Image Models},
98
+ year = {2019},
99
+ publisher = {GitHub},
100
+ journal = {GitHub repository},
101
+ doi = {10.5281/zenodo.4414861},
102
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
103
+ }
104
+ ```
config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "vit_large_patch16_224",
3
+ "num_classes": 0,
4
+ "num_features": 1024,
5
+ "global_pool": "token",
6
+ "pretrained_cfg": {
7
+ "tag": "orig_in21k",
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.5,
20
+ 0.5,
21
+ 0.5
22
+ ],
23
+ "std": [
24
+ 0.5,
25
+ 0.5,
26
+ 0.5
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:c2acf9abed0c497bf39c04dbf726a2b7c27060c82cae8a74c125ddd126756028
3
+ size 1213234512
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:56edbc9053b1fdd60dcfadc05f8c83cadf43de3e257605af3d86a157eda1bb75
3
+ size 1213317282