timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
42859d4
1 Parent(s): c751380
Files changed (4) hide show
  1. README.md +127 -0
  2. config.json +35 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_name: timm
6
+ license: apache-2.0
7
+ datasets:
8
+ - imagenet-1k
9
+ ---
10
+ # Model card for tresnet_xl.miil_in1k_448
11
+
12
+ A TResNet image classification model. Trained on ImageNet-1k by paper authors.
13
+
14
+ 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.
15
+
16
+ ## Model Details
17
+ - **Model Type:** Image classification / feature backbone
18
+ - **Model Stats:**
19
+ - Params (M): 78.4
20
+ - GMACs: 60.8
21
+ - Activations (M): 61.3
22
+ - Image size: 448 x 448
23
+ - **Papers:**
24
+ - TResNet: High Performance GPU-Dedicated Architecture: https://arxiv.org/abs/2003.13630
25
+ - **Dataset:** ImageNet-1k
26
+ - **Original:** https://github.com/Alibaba-MIIL/TResNet
27
+
28
+ ## Model Usage
29
+ ### Image Classification
30
+ ```python
31
+ from urllib.request import urlopen
32
+ from PIL import Image
33
+ import timm
34
+
35
+ img = Image.open(urlopen(
36
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
37
+ ))
38
+
39
+ model = timm.create_model('tresnet_xl.miil_in1k_448', pretrained=True)
40
+ model = model.eval()
41
+
42
+ # get model specific transforms (normalization, resize)
43
+ data_config = timm.data.resolve_model_data_config(model)
44
+ transforms = timm.data.create_transform(**data_config, is_training=False)
45
+
46
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
47
+
48
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
49
+ ```
50
+
51
+ ### Feature Map Extraction
52
+ ```python
53
+ from urllib.request import urlopen
54
+ from PIL import Image
55
+ import timm
56
+
57
+ img = Image.open(urlopen(
58
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
59
+ ))
60
+
61
+ model = timm.create_model(
62
+ 'tresnet_xl.miil_in1k_448',
63
+ pretrained=True,
64
+ features_only=True,
65
+ )
66
+ model = model.eval()
67
+
68
+ # get model specific transforms (normalization, resize)
69
+ data_config = timm.data.resolve_model_data_config(model)
70
+ transforms = timm.data.create_transform(**data_config, is_training=False)
71
+
72
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
73
+
74
+ for o in output:
75
+ # print shape of each feature map in output
76
+ # e.g.:
77
+ # torch.Size([1, 83, 112, 112])
78
+ # torch.Size([1, 166, 56, 56])
79
+ # torch.Size([1, 1328, 28, 28])
80
+ # torch.Size([1, 2656, 14, 14])
81
+
82
+ print(o.shape)
83
+ ```
84
+
85
+ ### Image Embeddings
86
+ ```python
87
+ from urllib.request import urlopen
88
+ from PIL import Image
89
+ import timm
90
+
91
+ img = Image.open(urlopen(
92
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
93
+ ))
94
+
95
+ model = timm.create_model(
96
+ 'tresnet_xl.miil_in1k_448',
97
+ pretrained=True,
98
+ num_classes=0, # remove classifier nn.Linear
99
+ )
100
+ model = model.eval()
101
+
102
+ # get model specific transforms (normalization, resize)
103
+ data_config = timm.data.resolve_model_data_config(model)
104
+ transforms = timm.data.create_transform(**data_config, is_training=False)
105
+
106
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
107
+
108
+ # or equivalently (without needing to set num_classes=0)
109
+
110
+ output = model.forward_features(transforms(img).unsqueeze(0))
111
+ # output is unpooled, a (1, 2656, 14, 14) shaped tensor
112
+
113
+ output = model.forward_head(output, pre_logits=True)
114
+ # output is a (1, num_features) shaped tensor
115
+ ```
116
+
117
+ ## Citation
118
+ ```bibtex
119
+ @misc{ridnik2020tresnet,
120
+ title={TResNet: High Performance GPU-Dedicated Architecture},
121
+ author={Tal Ridnik and Hussam Lawen and Asaf Noy and Itamar Friedman},
122
+ year={2020},
123
+ eprint={2003.13630},
124
+ archivePrefix={arXiv},
125
+ primaryClass={cs.CV}
126
+ }
127
+ ```
config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "tresnet_xl",
3
+ "num_classes": 1000,
4
+ "num_features": 2656,
5
+ "pretrained_cfg": {
6
+ "tag": "miil_in1k_448",
7
+ "custom_load": false,
8
+ "input_size": [
9
+ 3,
10
+ 448,
11
+ 448
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
+ 14,
30
+ 14
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:8d3422ecf0ab763218137d407f21d207871ec3843ee2dcbb2405d8040ed96574
3
+ size 314352064
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a9b6711ca5b8b88273af6a106821637a4ed1afe80b636a8a293703491e6a9658
3
+ size 314534541