timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
a6ccb15
1 Parent(s): 1ddc558
Files changed (4) hide show
  1. README.md +142 -0
  2. config.json +35 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_name: timm
6
+ license: apache-2.0
7
+ datasets:
8
+ - imagenet-1k
9
+ - imagenet-21k-p
10
+ ---
11
+ # Model card for tresnet_v2_l.miil_in21k_ft_in1k
12
+
13
+ A TResNet image classification model. Pretrained on ImageNet-21K-P ("ImageNet-21K Pretraining for the Masses", a 11k subset of ImageNet-22k) and fine-tuned on ImageNet-1k by paper authors.
14
+
15
+ The weights for this model have been remapped and modified from the originals to work with standard BatchNorm instead of InplaceABN. `inplace_abn` can be problematic to build recently and ends up slower with `memory_format=channels_last`, torch.compile(), etc.
16
+
17
+ ## Model Details
18
+ - **Model Type:** Image classification / feature backbone
19
+ - **Model Stats:**
20
+ - Params (M): 46.2
21
+ - GMACs: 8.8
22
+ - Activations (M): 16.3
23
+ - Image size: 224 x 224
24
+ - **Papers:**
25
+ - TResNet: High Performance GPU-Dedicated Architecture: https://arxiv.org/abs/2003.13630
26
+ - ImageNet-21K Pretraining for the Masses: https://arxiv.org/abs/2104.10972
27
+ - **Dataset:** ImageNet-1k
28
+ - **Pretrain Dataset:** ImageNet-21K-P
29
+ - **Original:**
30
+ - https://github.com/Alibaba-MIIL/TResNet
31
+ - https://github.com/Alibaba-MIIL/ImageNet21K
32
+
33
+ ## Model Usage
34
+ ### Image Classification
35
+ ```python
36
+ from urllib.request import urlopen
37
+ from PIL import Image
38
+ import timm
39
+
40
+ img = Image.open(urlopen(
41
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
42
+ ))
43
+
44
+ model = timm.create_model('tresnet_v2_l.miil_in21k_ft_in1k', pretrained=True)
45
+ model = model.eval()
46
+
47
+ # get model specific transforms (normalization, resize)
48
+ data_config = timm.data.resolve_model_data_config(model)
49
+ transforms = timm.data.create_transform(**data_config, is_training=False)
50
+
51
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
52
+
53
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
54
+ ```
55
+
56
+ ### Feature Map Extraction
57
+ ```python
58
+ from urllib.request import urlopen
59
+ from PIL import Image
60
+ import timm
61
+
62
+ img = Image.open(urlopen(
63
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
64
+ ))
65
+
66
+ model = timm.create_model(
67
+ 'tresnet_v2_l.miil_in21k_ft_in1k',
68
+ pretrained=True,
69
+ features_only=True,
70
+ )
71
+ model = model.eval()
72
+
73
+ # get model specific transforms (normalization, resize)
74
+ data_config = timm.data.resolve_model_data_config(model)
75
+ transforms = timm.data.create_transform(**data_config, is_training=False)
76
+
77
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
78
+
79
+ for o in output:
80
+ # print shape of each feature map in output
81
+ # e.g.:
82
+ # torch.Size([1, 256, 56, 56])
83
+ # torch.Size([1, 512, 28, 28])
84
+ # torch.Size([1, 1024, 14, 14])
85
+ # torch.Size([1, 2048, 7, 7])
86
+
87
+ print(o.shape)
88
+ ```
89
+
90
+ ### Image Embeddings
91
+ ```python
92
+ from urllib.request import urlopen
93
+ from PIL import Image
94
+ import timm
95
+
96
+ img = Image.open(urlopen(
97
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
98
+ ))
99
+
100
+ model = timm.create_model(
101
+ 'tresnet_v2_l.miil_in21k_ft_in1k',
102
+ pretrained=True,
103
+ num_classes=0, # remove classifier nn.Linear
104
+ )
105
+ model = model.eval()
106
+
107
+ # get model specific transforms (normalization, resize)
108
+ data_config = timm.data.resolve_model_data_config(model)
109
+ transforms = timm.data.create_transform(**data_config, is_training=False)
110
+
111
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
112
+
113
+ # or equivalently (without needing to set num_classes=0)
114
+
115
+ output = model.forward_features(transforms(img).unsqueeze(0))
116
+ # output is unpooled, a (1, 2048, 7, 7) shaped tensor
117
+
118
+ output = model.forward_head(output, pre_logits=True)
119
+ # output is a (1, num_features) shaped tensor
120
+ ```
121
+
122
+ ## Citation
123
+ ```bibtex
124
+ @misc{ridnik2020tresnet,
125
+ title={TResNet: High Performance GPU-Dedicated Architecture},
126
+ author={Tal Ridnik and Hussam Lawen and Asaf Noy and Itamar Friedman},
127
+ year={2020},
128
+ eprint={2003.13630},
129
+ archivePrefix={arXiv},
130
+ primaryClass={cs.CV}
131
+ }
132
+ ```
133
+ ```bibtex
134
+ @misc{ridnik2021imagenet21k,
135
+ title={ImageNet-21K Pretraining for the Masses},
136
+ author={Tal Ridnik and Emanuel Ben-Baruch and Asaf Noy and Lihi Zelnik-Manor},
137
+ year={2021},
138
+ eprint={2104.10972},
139
+ archivePrefix={arXiv},
140
+ primaryClass={cs.CV}
141
+ }
142
+ ```
config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "tresnet_v2_l",
3
+ "num_classes": 1000,
4
+ "num_features": 2048,
5
+ "pretrained_cfg": {
6
+ "tag": "miil_in21k_ft_in1k",
7
+ "custom_load": false,
8
+ "input_size": [
9
+ 3,
10
+ 224,
11
+ 224
12
+ ],
13
+ "fixed_input_size": false,
14
+ "interpolation": "bilinear",
15
+ "crop_pct": 0.875,
16
+ "crop_mode": "center",
17
+ "mean": [
18
+ 0.0,
19
+ 0.0,
20
+ 0.0
21
+ ],
22
+ "std": [
23
+ 1.0,
24
+ 1.0,
25
+ 1.0
26
+ ],
27
+ "num_classes": 1000,
28
+ "pool_size": [
29
+ 7,
30
+ 7
31
+ ],
32
+ "first_conv": "body.conv1.conv",
33
+ "classifier": "head.fc"
34
+ }
35
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c9c65a12d4d20e71162143eecc7346913c1d12b79cd55ab22b6ee719f3b53eba
3
+ size 185196180
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c6adb413fdd594eb68bf6f240f73c0aff80561ddf6fb077e49294f350822eb18
3
+ size 185392117