timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
3106863
1 Parent(s): dff79d6
Files changed (4) hide show
  1. README.md +163 -0
  2. config.json +41 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_tag: timm
6
+ license: apache-2.0
7
+ datasets:
8
+ - imagenet-1k
9
+ ---
10
+ # Model card for gcresnext26ts.ch_in1k
11
+
12
+ A GC-ResNeXt image classification model (ResNeXt with 'Global Context' attention). This model features a tiered 3-layer stem and SiLU activations. Trained on ImageNet-1k by Ross Wightman in `timm`.
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): 10.5
34
+ - GMACs: 2.4
35
+ - Activations (M): 10.5
36
+ - Image size: train = 256 x 256, test = 288 x 288
37
+ - **Papers:**
38
+ - GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond: https://arxiv.org/abs/1904.11492
39
+ - Aggregated Residual Transformations for Deep Neural Networks: https://arxiv.org/abs/1611.05431
40
+ - **Dataset:** ImageNet-1k
41
+ - **Original:** https://github.com/huggingface/pytorch-image-models
42
+
43
+ ## Model Usage
44
+ ### Image Classification
45
+ ```python
46
+ from urllib.request import urlopen
47
+ from PIL import Image
48
+ import timm
49
+
50
+ img = Image.open(urlopen(
51
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
52
+ ))
53
+
54
+ model = timm.create_model('gcresnext26ts.ch_in1k', pretrained=True)
55
+ model = model.eval()
56
+
57
+ # get model specific transforms (normalization, resize)
58
+ data_config = timm.data.resolve_model_data_config(model)
59
+ transforms = timm.data.create_transform(**data_config, is_training=False)
60
+
61
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
62
+
63
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
64
+ ```
65
+
66
+ ### Feature Map Extraction
67
+ ```python
68
+ from urllib.request import urlopen
69
+ from PIL import Image
70
+ import timm
71
+
72
+ img = Image.open(urlopen(
73
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
74
+ ))
75
+
76
+ model = timm.create_model(
77
+ 'gcresnext26ts.ch_in1k',
78
+ pretrained=True,
79
+ features_only=True,
80
+ )
81
+ model = model.eval()
82
+
83
+ # get model specific transforms (normalization, resize)
84
+ data_config = timm.data.resolve_model_data_config(model)
85
+ transforms = timm.data.create_transform(**data_config, is_training=False)
86
+
87
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
88
+
89
+ for o in output:
90
+ # print shape of each feature map in output
91
+ # e.g.:
92
+ # torch.Size([1, 64, 128, 128])
93
+ # torch.Size([1, 256, 64, 64])
94
+ # torch.Size([1, 512, 32, 32])
95
+ # torch.Size([1, 1024, 16, 16])
96
+ # torch.Size([1, 2048, 8, 8])
97
+
98
+ print(o.shape)
99
+ ```
100
+
101
+ ### Image Embeddings
102
+ ```python
103
+ from urllib.request import urlopen
104
+ from PIL import Image
105
+ import timm
106
+
107
+ img = Image.open(urlopen(
108
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
109
+ ))
110
+
111
+ model = timm.create_model(
112
+ 'gcresnext26ts.ch_in1k',
113
+ pretrained=True,
114
+ num_classes=0, # remove classifier nn.Linear
115
+ )
116
+ model = model.eval()
117
+
118
+ # get model specific transforms (normalization, resize)
119
+ data_config = timm.data.resolve_model_data_config(model)
120
+ transforms = timm.data.create_transform(**data_config, is_training=False)
121
+
122
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
123
+
124
+ # or equivalently (without needing to set num_classes=0)
125
+
126
+ output = model.forward_features(transforms(img).unsqueeze(0))
127
+ # output is unpooled, a (1, 2048, 8, 8) shaped tensor
128
+
129
+ output = model.forward_head(output, pre_logits=True)
130
+ # output is a (1, num_features) shaped tensor
131
+ ```
132
+
133
+ ## Model Comparison
134
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
135
+
136
+ ## Citation
137
+ ```bibtex
138
+ @misc{rw2019timm,
139
+ author = {Ross Wightman},
140
+ title = {PyTorch Image Models},
141
+ year = {2019},
142
+ publisher = {GitHub},
143
+ journal = {GitHub repository},
144
+ doi = {10.5281/zenodo.4414861},
145
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
146
+ }
147
+ ```
148
+ ```bibtex
149
+ @article{cao2019GCNet,
150
+ title={GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond},
151
+ author={Cao, Yue and Xu, Jiarui and Lin, Stephen and Wei, Fangyun and Hu, Han},
152
+ journal={arXiv preprint arXiv:1904.11492},
153
+ year={2019}
154
+ }
155
+ ```
156
+ ```bibtex
157
+ @article{Xie2016,
158
+ title={Aggregated Residual Transformations for Deep Neural Networks},
159
+ author={Saining Xie and Ross Girshick and Piotr Dollár and Zhuowen Tu and Kaiming He},
160
+ journal={arXiv preprint arXiv:1611.05431},
161
+ year={2016}
162
+ }
163
+ ```
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "gcresnext26ts",
3
+ "num_classes": 1000,
4
+ "num_features": 2048,
5
+ "pretrained_cfg": {
6
+ "tag": "ch_in1k",
7
+ "custom_load": false,
8
+ "input_size": [
9
+ 3,
10
+ 256,
11
+ 256
12
+ ],
13
+ "test_input_size": [
14
+ 3,
15
+ 288,
16
+ 288
17
+ ],
18
+ "fixed_input_size": false,
19
+ "interpolation": "bicubic",
20
+ "crop_pct": 0.9,
21
+ "test_crop_pct": 1.0,
22
+ "crop_mode": "center",
23
+ "mean": [
24
+ 0.485,
25
+ 0.456,
26
+ 0.406
27
+ ],
28
+ "std": [
29
+ 0.229,
30
+ 0.224,
31
+ 0.225
32
+ ],
33
+ "num_classes": 1000,
34
+ "pool_size": [
35
+ 8,
36
+ 8
37
+ ],
38
+ "first_conv": "stem.conv1.conv",
39
+ "classifier": "head.fc"
40
+ }
41
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:09ba5886f169976e92f730d44e9daf2db1bf160f01905e1f4a3fcbf34f94e818
3
+ size 42055590
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:15b40aa1251b83ff1cae40fdd670eb4980378af493d6bf0da5dc4ffd48331c66
3
+ size 42121661