timm
/

Image Classification
timm
PyTorch
Safetensors
Transformers
rwightman HF Staff commited on
Commit
5ba2045
·
1 Parent(s): c634a85
Files changed (4) hide show
  1. README.md +150 -0
  2. config.json +41 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_tag: timm
6
+ license: apache-2.0
7
+ ---
8
+ # Model card for cs3edgenet_x.c2_in1k
9
+
10
+ A CS3-EdgeNet (Cross-Stage-Partial w/ 3 convolutions and Squeeze-and-Excitation channel attention) image classification model. `EdgeNet` models are similar to `DarkNet` but use a MobileNet-V1 like 3x3 + 1x1 residual block instead of a 1x1 + 3x3 block. Trained on ImageNet-1k in `timm` using recipe template described below.
11
+
12
+ Recipe details:
13
+ * Based on [ResNet Strikes Back](https://arxiv.org/abs/2110.00476) `C` recipes w/o repeat-aug and stronger mixup
14
+ * SGD (w/ Nesterov) optimizer and AGC (adaptive gradient clipping)
15
+ * Cosine LR schedule with warmup
16
+
17
+
18
+ ## Model Details
19
+ - **Model Type:** Image classification / feature backbone
20
+ - **Model Stats:**
21
+ - Params (M): 47.8
22
+ - GMACs: 11.5
23
+ - Activations (M): 12.9
24
+ - Image size: train = 256 x 256, test = 288 x 288
25
+ - **Papers:**
26
+ - CSPNet: A New Backbone that can Enhance Learning Capability of CNN: https://arxiv.org/abs/1911.11929
27
+ - ResNet strikes back: An improved training procedure in timm: https://arxiv.org/abs/2110.00476
28
+ - **Original:** https://github.com/huggingface/pytorch-image-models
29
+
30
+ ## Model Usage
31
+ ### Image Classification
32
+ ```python
33
+ from urllib.request import urlopen
34
+ from PIL import Image
35
+ import timm
36
+
37
+ img = Image.open(urlopen(
38
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
39
+ ))
40
+
41
+ model = timm.create_model('cs3edgenet_x.c2_in1k', pretrained=True)
42
+ model = model.eval()
43
+
44
+ # get model specific transforms (normalization, resize)
45
+ data_config = timm.data.resolve_model_data_config(model)
46
+ transforms = timm.data.create_transform(**data_config, is_training=False)
47
+
48
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
49
+
50
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
51
+ ```
52
+
53
+ ### Feature Map Extraction
54
+ ```python
55
+ from urllib.request import urlopen
56
+ from PIL import Image
57
+ import timm
58
+
59
+ img = Image.open(urlopen(
60
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
61
+ ))
62
+
63
+ model = timm.create_model(
64
+ 'cs3edgenet_x.c2_in1k',
65
+ pretrained=True,
66
+ features_only=True,
67
+ )
68
+ model = model.eval()
69
+
70
+ # get model specific transforms (normalization, resize)
71
+ data_config = timm.data.resolve_model_data_config(model)
72
+ transforms = timm.data.create_transform(**data_config, is_training=False)
73
+
74
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
75
+
76
+ for o in output:
77
+ # print shape of each feature map in output
78
+ # e.g.:
79
+ # torch.Size([1, 80, 128, 128])
80
+ # torch.Size([1, 160, 64, 64])
81
+ # torch.Size([1, 320, 32, 32])
82
+ # torch.Size([1, 640, 16, 16])
83
+ # torch.Size([1, 1280, 8, 8])
84
+
85
+ print(o.shape)
86
+ ```
87
+
88
+ ### Image Embeddings
89
+ ```python
90
+ from urllib.request import urlopen
91
+ from PIL import Image
92
+ import timm
93
+
94
+ img = Image.open(urlopen(
95
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
96
+ ))
97
+
98
+ model = timm.create_model(
99
+ 'cs3edgenet_x.c2_in1k',
100
+ pretrained=True,
101
+ num_classes=0, # remove classifier nn.Linear
102
+ )
103
+ model = model.eval()
104
+
105
+ # get model specific transforms (normalization, resize)
106
+ data_config = timm.data.resolve_model_data_config(model)
107
+ transforms = timm.data.create_transform(**data_config, is_training=False)
108
+
109
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
110
+
111
+ # or equivalently (without needing to set num_classes=0)
112
+
113
+ output = model.forward_features(transforms(img).unsqueeze(0))
114
+ # output is unpooled, a (1, 1280, 8, 8) shaped tensor
115
+
116
+ output = model.forward_head(output, pre_logits=True)
117
+ # output is a (1, num_features) shaped tensor
118
+ ```
119
+
120
+ ## Model Comparison
121
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
122
+
123
+ ## Citation
124
+ ```bibtex
125
+ @article{Wang2019CSPNetAN,
126
+ title={CSPNet: A New Backbone that can Enhance Learning Capability of CNN},
127
+ author={Chien-Yao Wang and Hong-Yuan Mark Liao and I-Hau Yeh and Yueh-Hua Wu and Ping-Yang Chen and Jun-Wei Hsieh},
128
+ journal={2020 IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops (CVPRW)},
129
+ year={2019},
130
+ pages={1571-1580}
131
+ }
132
+ ```
133
+ ```bibtex
134
+ @misc{rw2019timm,
135
+ author = {Ross Wightman},
136
+ title = {PyTorch Image Models},
137
+ year = {2019},
138
+ publisher = {GitHub},
139
+ journal = {GitHub repository},
140
+ doi = {10.5281/zenodo.4414861},
141
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
142
+ }
143
+ ```
144
+ ```bibtex
145
+ @inproceedings{wightman2021resnet,
146
+ title={ResNet strikes back: An improved training procedure in timm},
147
+ author={Wightman, Ross and Touvron, Hugo and Jegou, Herve},
148
+ booktitle={NeurIPS 2021 Workshop on ImageNet: Past, Present, and Future}
149
+ }
150
+ ```
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "cs3edgenet_x",
3
+ "num_classes": 1000,
4
+ "num_features": 1280,
5
+ "pretrained_cfg": {
6
+ "tag": "c2_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.887,
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:a7db8a6df18d3221487d7763361a934869007730ade69d2c7524dc2aa0dc972c
3
+ size 191508378
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:db664e47c0aad4e1a4075d9b3e7c7116798069638e8b191059b6724090a0931a
3
+ size 191606245