timm
/

Image Classification
timm
PyTorch
Safetensors
Transformers
rwightman HF staff commited on
Commit
1144268
·
1 Parent(s): 1a173f5
Files changed (4) hide show
  1. README.md +161 -0
  2. config.json +35 -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 cspdarknet53.ra_in1k
9
+
10
+ A CSP-DarkNet (Cross-Stage-Partial) image classification model. Trained on ImageNet-1k in `timm` using recipe template described below.
11
+
12
+ Recipe details:
13
+ * RandAugment `RA` recipe. Inspired by and evolved from EfficientNet RandAugment recipes. Published as `B` recipe in [ResNet Strikes Back](https://arxiv.org/abs/2110.00476).
14
+ * RMSProp (TF 1.0 behaviour) optimizer, EMA weight averaging
15
+ * Step (exponential decay w/ staircase) LR schedule with warmup
16
+
17
+
18
+ ## Model Details
19
+ - **Model Type:** Image classification / feature backbone
20
+ - **Model Stats:**
21
+ - Params (M): 27.6
22
+ - GMACs: 6.6
23
+ - Activations (M): 16.8
24
+ - Image size: 256 x 256
25
+ - **Papers:**
26
+ - CSPNet: A New Backbone that can Enhance Learning Capability of CNN: https://arxiv.org/abs/1911.11929
27
+ - YOLOv3: An Incremental Improvement: https://arxiv.org/abs/1804.02767
28
+ - ResNet strikes back: An improved training procedure in timm: https://arxiv.org/abs/2110.00476
29
+ - **Original:** https://github.com/huggingface/pytorch-image-models
30
+
31
+ ## Model Usage
32
+ ### Image Classification
33
+ ```python
34
+ from urllib.request import urlopen
35
+ from PIL import Image
36
+ import timm
37
+
38
+ img = Image.open(urlopen(
39
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
40
+ ))
41
+
42
+ model = timm.create_model('cspdarknet53.ra_in1k', pretrained=True)
43
+ model = model.eval()
44
+
45
+ # get model specific transforms (normalization, resize)
46
+ data_config = timm.data.resolve_model_data_config(model)
47
+ transforms = timm.data.create_transform(**data_config, is_training=False)
48
+
49
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
50
+
51
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
52
+ ```
53
+
54
+ ### Feature Map Extraction
55
+ ```python
56
+ from urllib.request import urlopen
57
+ from PIL import Image
58
+ import timm
59
+
60
+ img = Image.open(urlopen(
61
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
62
+ ))
63
+
64
+ model = timm.create_model(
65
+ 'cspdarknet53.ra_in1k',
66
+ pretrained=True,
67
+ features_only=True,
68
+ )
69
+ model = model.eval()
70
+
71
+ # get model specific transforms (normalization, resize)
72
+ data_config = timm.data.resolve_model_data_config(model)
73
+ transforms = timm.data.create_transform(**data_config, is_training=False)
74
+
75
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
76
+
77
+ for o in output:
78
+ # print shape of each feature map in output
79
+ # e.g.:
80
+ # torch.Size([1, 32, 256, 256])
81
+ # torch.Size([1, 64, 128, 128])
82
+ # torch.Size([1, 128, 64, 64])
83
+ # torch.Size([1, 256, 32, 32])
84
+ # torch.Size([1, 512, 16, 16])
85
+ # torch.Size([1, 1024, 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
+ 'cspdarknet53.ra_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, 1024, 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
+ @article{Redmon2018YOLOv3AI,
137
+ title={YOLOv3: An Incremental Improvement},
138
+ author={Joseph Redmon and Ali Farhadi},
139
+ journal={ArXiv},
140
+ year={2018},
141
+ volume={abs/1804.02767}
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
+ ```
151
+ ```bibtex
152
+ @misc{rw2019timm,
153
+ author = {Ross Wightman},
154
+ title = {PyTorch Image Models},
155
+ year = {2019},
156
+ publisher = {GitHub},
157
+ journal = {GitHub repository},
158
+ doi = {10.5281/zenodo.4414861},
159
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
160
+ }
161
+ ```
config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "cspdarknet53",
3
+ "num_classes": 1000,
4
+ "num_features": 1024,
5
+ "pretrained_cfg": {
6
+ "tag": "ra_in1k",
7
+ "custom_load": false,
8
+ "input_size": [
9
+ 3,
10
+ 256,
11
+ 256
12
+ ],
13
+ "fixed_input_size": false,
14
+ "interpolation": "bilinear",
15
+ "crop_pct": 0.887,
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
+ 8,
30
+ 8
31
+ ],
32
+ "first_conv": "stem.conv1.conv",
33
+ "classifier": "head.fc"
34
+ }
35
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:685ad4726e6e8785ecb778ab5d3a045e16d317be170e0f2caeb1f58800885546
3
+ size 110752004
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:394a9371c7c52236fefe087aba296f60ad7401017b849916f4f9613fe0722d8c
3
+ size 110858269