timm
/

Image Classification
timm
PyTorch
Safetensors
Transformers
rwightman HF Staff commited on
Commit
d7cf04d
·
1 Parent(s): 015cfce
Files changed (4) hide show
  1. README.md +138 -0
  2. config.json +35 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_name: timm
6
+ license: unknown
7
+ datasets:
8
+ - imagenet-1k
9
+ ---
10
+ # Model card for dla60_res2net.in1k
11
+
12
+ A DLA (Deep Layer Aggregation) image classification model with Res2Net blocks. Trained on ImageNet-1k by Res2Net paper authors.
13
+
14
+ ## Model Details
15
+ - **Model Type:** Image classification / feature backbone
16
+ - **Model Stats:**
17
+ - Params (M): 20.8
18
+ - GMACs: 4.1
19
+ - Activations (M): 12.3
20
+ - Image size: 224 x 224
21
+ - **Papers:**
22
+ - Deep Layer Aggregation: https://arxiv.org/abs/1707.06484
23
+ - Res2Net: A New Multi-scale Backbone Architecture: https://arxiv.org/abs/1904.01169
24
+ - **Original:**
25
+ - https://github.com/ucbdrive/dla
26
+ - https://github.com/gasvn/Res2Net/
27
+ - **Dataset:** ImageNet-1k
28
+
29
+ ## Model Usage
30
+ ### Image Classification
31
+ ```python
32
+ from urllib.request import urlopen
33
+ from PIL import Image
34
+ import timm
35
+
36
+ img = Image.open(urlopen(
37
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
38
+ ))
39
+
40
+ model = timm.create_model('dla60_res2net.in1k', pretrained=True)
41
+ model = model.eval()
42
+
43
+ # get model specific transforms (normalization, resize)
44
+ data_config = timm.data.resolve_model_data_config(model)
45
+ transforms = timm.data.create_transform(**data_config, is_training=False)
46
+
47
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
48
+
49
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
50
+ ```
51
+
52
+ ### Feature Map Extraction
53
+ ```python
54
+ from urllib.request import urlopen
55
+ from PIL import Image
56
+ import timm
57
+
58
+ img = Image.open(urlopen(
59
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
60
+ ))
61
+
62
+ model = timm.create_model(
63
+ 'dla60_res2net.in1k',
64
+ pretrained=True,
65
+ features_only=True,
66
+ )
67
+ model = model.eval()
68
+
69
+ # get model specific transforms (normalization, resize)
70
+ data_config = timm.data.resolve_model_data_config(model)
71
+ transforms = timm.data.create_transform(**data_config, is_training=False)
72
+
73
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
74
+
75
+ for o in output:
76
+ # print shape of each feature map in output
77
+ # e.g.:
78
+ # torch.Size([1, 32, 112, 112])
79
+ # torch.Size([1, 128, 56, 56])
80
+ # torch.Size([1, 256, 28, 28])
81
+ # torch.Size([1, 512, 14, 14])
82
+ # torch.Size([1, 1024, 7, 7])
83
+
84
+ print(o.shape)
85
+ ```
86
+
87
+ ### Image Embeddings
88
+ ```python
89
+ from urllib.request import urlopen
90
+ from PIL import Image
91
+ import timm
92
+
93
+ img = Image.open(urlopen(
94
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
95
+ ))
96
+
97
+ model = timm.create_model(
98
+ 'dla60_res2net.in1k',
99
+ pretrained=True,
100
+ num_classes=0, # remove classifier nn.Linear
101
+ )
102
+ model = model.eval()
103
+
104
+ # get model specific transforms (normalization, resize)
105
+ data_config = timm.data.resolve_model_data_config(model)
106
+ transforms = timm.data.create_transform(**data_config, is_training=False)
107
+
108
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
109
+
110
+ # or equivalently (without needing to set num_classes=0)
111
+
112
+ output = model.forward_features(transforms(img).unsqueeze(0))
113
+ # output is unpooled, a (1, 1024, 7, 7) shaped tensor
114
+
115
+ output = model.forward_head(output, pre_logits=True)
116
+ # output is a (1, num_features) shaped tensor
117
+ ```
118
+
119
+ ## Model Comparison
120
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
121
+
122
+ ## Citation
123
+ ```bibtex
124
+ @inproceedings{yu2018deep,
125
+ title={Deep layer aggregation},
126
+ author={Yu, Fisher and Wang, Dequan and Shelhamer, Evan and Darrell, Trevor},
127
+ booktitle={Proceedings of the IEEE conference on computer vision and pattern recognition},
128
+ year={2018}
129
+ }
130
+ ```
131
+ ```bibtex
132
+ @article{gao2019res2net,
133
+ title={Res2Net: A New Multi-scale Backbone Architecture},
134
+ author={Gao, Shang-Hua and Cheng, Ming-Ming and Zhao, Kai and Zhang, Xin-Yu and Yang, Ming-Hsuan and Torr, Philip},
135
+ journal={IEEE TPAMI},
136
+ doi={10.1109/TPAMI.2019.2938758},
137
+ }
138
+ ```
config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "dla60_res2net",
3
+ "num_classes": 1000,
4
+ "num_features": 1024,
5
+ "pretrained_cfg": {
6
+ "tag": "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.485,
19
+ 0.456,
20
+ 0.406
21
+ ],
22
+ "std": [
23
+ 0.229,
24
+ 0.224,
25
+ 0.225
26
+ ],
27
+ "num_classes": 1000,
28
+ "pool_size": [
29
+ 7,
30
+ 7
31
+ ],
32
+ "first_conv": "base_layer.0",
33
+ "classifier": "fc"
34
+ }
35
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:965c32cca3dcffb627341784c4d6c53351e0a0438d71754e4060f26b7e73dcb7
3
+ size 83646654
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:07b3edf0544e66741a3f430fa074c093b757685b621a5b497017092c4130228d
3
+ size 83779709