timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
962d840
1 Parent(s): 021e741
Files changed (4) hide show
  1. README.md +161 -0
  2. config.json +41 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_tag: timm
6
+ license: apache-2.0
7
+ ---
8
+ # Model card for cs3darknet_x.c2ns_in1k
9
+
10
+ A CS3-DarkNet (Cross-Stage-Partial w/ 3 convolutions) image classification model. 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
+ * No stochastic depth used in this `ns` variation of the recipe
16
+ * Cosine LR schedule with warmup
17
+
18
+
19
+ ## Model Details
20
+ - **Model Type:** Image classification / feature backbone
21
+ - **Model Stats:**
22
+ - Params (M): 35.0
23
+ - GMACs: 8.4
24
+ - Activations (M): 11.3
25
+ - Image size: train = 256 x 256, test = 288 x 288
26
+ - **Papers:**
27
+ - CSPNet: A New Backbone that can Enhance Learning Capability of CNN: https://arxiv.org/abs/1911.11929
28
+ - YOLOv3: An Incremental Improvement: https://arxiv.org/abs/1804.02767
29
+ - ResNet strikes back: An improved training procedure in timm: https://arxiv.org/abs/2110.00476
30
+ - **Original:** https://github.com/huggingface/pytorch-image-models
31
+
32
+ ## Model Usage
33
+ ### Image Classification
34
+ ```python
35
+ from urllib.request import urlopen
36
+ from PIL import Image
37
+ import timm
38
+
39
+ img = Image.open(urlopen(
40
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
41
+ ))
42
+
43
+ model = timm.create_model('cs3darknet_x.c2ns_in1k', pretrained=True)
44
+ model = model.eval()
45
+
46
+ # get model specific transforms (normalization, resize)
47
+ data_config = timm.data.resolve_model_data_config(model)
48
+ transforms = timm.data.create_transform(**data_config, is_training=False)
49
+
50
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
51
+
52
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
53
+ ```
54
+
55
+ ### Feature Map Extraction
56
+ ```python
57
+ from urllib.request import urlopen
58
+ from PIL import Image
59
+ import timm
60
+
61
+ img = Image.open(urlopen(
62
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
63
+ ))
64
+
65
+ model = timm.create_model(
66
+ 'cs3darknet_x.c2ns_in1k',
67
+ pretrained=True,
68
+ features_only=True,
69
+ )
70
+ model = model.eval()
71
+
72
+ # get model specific transforms (normalization, resize)
73
+ data_config = timm.data.resolve_model_data_config(model)
74
+ transforms = timm.data.create_transform(**data_config, is_training=False)
75
+
76
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
77
+
78
+ for o in output:
79
+ # print shape of each feature map in output
80
+ # e.g.:
81
+ # torch.Size([1, 80, 128, 128])
82
+ # torch.Size([1, 160, 64, 64])
83
+ # torch.Size([1, 320, 32, 32])
84
+ # torch.Size([1, 640, 16, 16])
85
+ # torch.Size([1, 1280, 8, 8])
86
+
87
+ print(o.shape)
88
+ ```
89
+
90
+ ### Image Embeddings
91
+ ```python
92
+ from urllib.request import urlopen
93
+ from PIL import Image
94
+ import timm
95
+
96
+ img = Image.open(urlopen(
97
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
98
+ ))
99
+
100
+ model = timm.create_model(
101
+ 'cs3darknet_x.c2ns_in1k',
102
+ pretrained=True,
103
+ num_classes=0, # remove classifier nn.Linear
104
+ )
105
+ model = model.eval()
106
+
107
+ # get model specific transforms (normalization, resize)
108
+ data_config = timm.data.resolve_model_data_config(model)
109
+ transforms = timm.data.create_transform(**data_config, is_training=False)
110
+
111
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
112
+
113
+ # or equivalently (without needing to set num_classes=0)
114
+
115
+ output = model.forward_features(transforms(img).unsqueeze(0))
116
+ # output is unpooled, a (1, 1280, 8, 8) shaped tensor
117
+
118
+ output = model.forward_head(output, pre_logits=True)
119
+ # output is a (1, num_features) shaped tensor
120
+ ```
121
+
122
+ ## Model Comparison
123
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
124
+
125
+ ## Citation
126
+ ```bibtex
127
+ @article{Wang2019CSPNetAN,
128
+ title={CSPNet: A New Backbone that can Enhance Learning Capability of CNN},
129
+ 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},
130
+ journal={2020 IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops (CVPRW)},
131
+ year={2019},
132
+ pages={1571-1580}
133
+ }
134
+ ```
135
+ ```bibtex
136
+ @misc{rw2019timm,
137
+ author = {Ross Wightman},
138
+ title = {PyTorch Image Models},
139
+ year = {2019},
140
+ publisher = {GitHub},
141
+ journal = {GitHub repository},
142
+ doi = {10.5281/zenodo.4414861},
143
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
144
+ }
145
+ ```
146
+ ```bibtex
147
+ @article{Redmon2018YOLOv3AI,
148
+ title={YOLOv3: An Incremental Improvement},
149
+ author={Joseph Redmon and Ali Farhadi},
150
+ journal={ArXiv},
151
+ year={2018},
152
+ volume={abs/1804.02767}
153
+ }
154
+ ```
155
+ ```bibtex
156
+ @inproceedings{wightman2021resnet,
157
+ title={ResNet strikes back: An improved training procedure in timm},
158
+ author={Wightman, Ross and Touvron, Hugo and Jegou, Herve},
159
+ booktitle={NeurIPS 2021 Workshop on ImageNet: Past, Present, and Future}
160
+ }
161
+ ```
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "cs3darknet_x",
3
+ "num_classes": 1000,
4
+ "num_features": 1280,
5
+ "pretrained_cfg": {
6
+ "tag": "c2ns_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.95,
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:918c5929f1800db9773e0dfbb999befdabab52a273d76c971d20019092e00f77
3
+ size 140381890
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1e605a7366c9fd64c7e484c5fdbda41d0ffb8c09c19972bac509a57bcd1492d4
3
+ size 140480229