timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
4a84d4d
1 Parent(s): f1505ee
Files changed (4) hide show
  1. README.md +155 -0
  2. config.json +39 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_tag: timm
6
+ license: mit
7
+ datasets:
8
+ - imagenet-1k
9
+ ---
10
+ # Model card for repvgg_a2.rvgg_in1k
11
+
12
+ A RepVGG image classification model. Trained on ImageNet-1k by paper authors.
13
+
14
+ This model architecture is implemented using `timm`'s flexible [BYOBNet (Bring-Your-Own-Blocks Network)](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/byobnet.py).
15
+
16
+ BYOBNet allows configuration of:
17
+ * block / stage layout
18
+ * stem layout
19
+ * output stride (dilation)
20
+ * activation and norm layers
21
+ * channel and spatial / self-attention layers
22
+
23
+ ...and also includes `timm` features common to many other architectures, including:
24
+ * stochastic depth
25
+ * gradient checkpointing
26
+ * layer-wise LR decay
27
+ * per-stage feature extraction
28
+
29
+
30
+ ## Model Details
31
+ - **Model Type:** Image classification / feature backbone
32
+ - **Model Stats:**
33
+ - Params (M): 28.2
34
+ - GMACs: 5.7
35
+ - Activations (M): 6.3
36
+ - Image size: 224 x 224
37
+ - **Papers:**
38
+ - RepVGG: Making VGG-style ConvNets Great Again: https://arxiv.org/abs/2101.03697
39
+ - **Dataset:** ImageNet-1k
40
+ - **Original:** https://github.com/DingXiaoH/RepVGG
41
+
42
+ ## Model Usage
43
+ ### Image Classification
44
+ ```python
45
+ from urllib.request import urlopen
46
+ from PIL import Image
47
+ import timm
48
+
49
+ img = Image.open(urlopen(
50
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
51
+ ))
52
+
53
+ model = timm.create_model('repvgg_a2.rvgg_in1k', pretrained=True)
54
+ model = model.eval()
55
+
56
+ # get model specific transforms (normalization, resize)
57
+ data_config = timm.data.resolve_model_data_config(model)
58
+ transforms = timm.data.create_transform(**data_config, is_training=False)
59
+
60
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
61
+
62
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
63
+ ```
64
+
65
+ ### Feature Map Extraction
66
+ ```python
67
+ from urllib.request import urlopen
68
+ from PIL import Image
69
+ import timm
70
+
71
+ img = Image.open(urlopen(
72
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
73
+ ))
74
+
75
+ model = timm.create_model(
76
+ 'repvgg_a2.rvgg_in1k',
77
+ pretrained=True,
78
+ features_only=True,
79
+ )
80
+ model = model.eval()
81
+
82
+ # get model specific transforms (normalization, resize)
83
+ data_config = timm.data.resolve_model_data_config(model)
84
+ transforms = timm.data.create_transform(**data_config, is_training=False)
85
+
86
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
87
+
88
+ for o in output:
89
+ # print shape of each feature map in output
90
+ # e.g.:
91
+ # torch.Size([1, 64, 112, 112])
92
+ # torch.Size([1, 96, 56, 56])
93
+ # torch.Size([1, 192, 28, 28])
94
+ # torch.Size([1, 384, 14, 14])
95
+ # torch.Size([1, 1408, 7, 7])
96
+
97
+ print(o.shape)
98
+ ```
99
+
100
+ ### Image Embeddings
101
+ ```python
102
+ from urllib.request import urlopen
103
+ from PIL import Image
104
+ import timm
105
+
106
+ img = Image.open(urlopen(
107
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
108
+ ))
109
+
110
+ model = timm.create_model(
111
+ 'repvgg_a2.rvgg_in1k',
112
+ pretrained=True,
113
+ num_classes=0, # remove classifier nn.Linear
114
+ )
115
+ model = model.eval()
116
+
117
+ # get model specific transforms (normalization, resize)
118
+ data_config = timm.data.resolve_model_data_config(model)
119
+ transforms = timm.data.create_transform(**data_config, is_training=False)
120
+
121
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
122
+
123
+ # or equivalently (without needing to set num_classes=0)
124
+
125
+ output = model.forward_features(transforms(img).unsqueeze(0))
126
+ # output is unpooled, a (1, 1408, 7, 7) shaped tensor
127
+
128
+ output = model.forward_head(output, pre_logits=True)
129
+ # output is a (1, num_features) shaped tensor
130
+ ```
131
+
132
+ ## Model Comparison
133
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
134
+
135
+ ## Citation
136
+ ```bibtex
137
+ @misc{rw2019timm,
138
+ author = {Ross Wightman},
139
+ title = {PyTorch Image Models},
140
+ year = {2019},
141
+ publisher = {GitHub},
142
+ journal = {GitHub repository},
143
+ doi = {10.5281/zenodo.4414861},
144
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
145
+ }
146
+ ```
147
+ ```bibtex
148
+ @inproceedings{ding2021repvgg,
149
+ title={Repvgg: Making vgg-style convnets great again},
150
+ author={Ding, Xiaohan and Zhang, Xiangyu and Ma, Ningning and Han, Jungong and Ding, Guiguang and Sun, Jian},
151
+ booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
152
+ pages={13733--13742},
153
+ year={2021}
154
+ }
155
+ ```
config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "repvgg_a2",
3
+ "num_classes": 1000,
4
+ "num_features": 1408,
5
+ "pretrained_cfg": {
6
+ "tag": "rvgg_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": [
33
+ "stem.conv_kxk.conv",
34
+ "stem.conv_1x1.conv"
35
+ ],
36
+ "classifier": "head.fc",
37
+ "license": "mit"
38
+ }
39
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a41919193e37f0f831acb5d8da43862275c9f8619cfa3bd4117aefa2ff61d0a4
3
+ size 113047706
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0cce225d92efc9a31ef24679eff0cb09253b1f753c79f29744d7ba5acf1864c1
3
+ size 113138121