rwightman HF staff commited on
Commit
2dfc548
1 Parent(s): 8e3a93a
Files changed (4) hide show
  1. README.md +151 -0
  2. config.json +41 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_tag: timm
6
+ license: apache-2.0
7
+ ---
8
+ # Model card for cs3se_edgenet_x.c2ns_in1k
9
+
10
+ A CS3-SE-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
+ * 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): 50.7
23
+ - GMACs: 11.5
24
+ - Activations (M): 12.9
25
+ - Image size: train = 256 x 256, test = 320 x 320
26
+ - **Papers:**
27
+ - CSPNet: A New Backbone that can Enhance Learning Capability of CNN: https://arxiv.org/abs/1911.11929
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('cs3se_edgenet_x.c2ns_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
+ 'cs3se_edgenet_x.c2ns_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, 80, 128, 128])
81
+ # torch.Size([1, 160, 64, 64])
82
+ # torch.Size([1, 320, 32, 32])
83
+ # torch.Size([1, 640, 16, 16])
84
+ # torch.Size([1, 1280, 8, 8])
85
+
86
+ print(o.shape)
87
+ ```
88
+
89
+ ### Image Embeddings
90
+ ```python
91
+ from urllib.request import urlopen
92
+ from PIL import Image
93
+ import timm
94
+
95
+ img = Image.open(urlopen(
96
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
97
+ ))
98
+
99
+ model = timm.create_model(
100
+ 'cs3se_edgenet_x.c2ns_in1k',
101
+ pretrained=True,
102
+ num_classes=0, # remove classifier nn.Linear
103
+ )
104
+ model = model.eval()
105
+
106
+ # get model specific transforms (normalization, resize)
107
+ data_config = timm.data.resolve_model_data_config(model)
108
+ transforms = timm.data.create_transform(**data_config, is_training=False)
109
+
110
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
111
+
112
+ # or equivalently (without needing to set num_classes=0)
113
+
114
+ output = model.forward_features(transforms(img).unsqueeze(0))
115
+ # output is unpooled, a (1, 1280, 8, 8) shaped tensor
116
+
117
+ output = model.forward_head(output, pre_logits=True)
118
+ # output is a (1, num_features) shaped tensor
119
+ ```
120
+
121
+ ## Model Comparison
122
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
123
+
124
+ ## Citation
125
+ ```bibtex
126
+ @article{Wang2019CSPNetAN,
127
+ title={CSPNet: A New Backbone that can Enhance Learning Capability of CNN},
128
+ 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},
129
+ journal={2020 IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops (CVPRW)},
130
+ year={2019},
131
+ pages={1571-1580}
132
+ }
133
+ ```
134
+ ```bibtex
135
+ @misc{rw2019timm,
136
+ author = {Ross Wightman},
137
+ title = {PyTorch Image Models},
138
+ year = {2019},
139
+ publisher = {GitHub},
140
+ journal = {GitHub repository},
141
+ doi = {10.5281/zenodo.4414861},
142
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
143
+ }
144
+ ```
145
+ ```bibtex
146
+ @inproceedings{wightman2021resnet,
147
+ title={ResNet strikes back: An improved training procedure in timm},
148
+ author={Wightman, Ross and Touvron, Hugo and Jegou, Herve},
149
+ booktitle={NeurIPS 2021 Workshop on ImageNet: Past, Present, and Future}
150
+ }
151
+ ```
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "cs3se_edgenet_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
+ 320,
16
+ 320
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:0cce4f72fab4e3a4607492ee8745e8f662a04a33ff0e7431d5307ee0d8aa123c
3
+ size 203120190
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f5bac4e622d80bf183b34dca3f18f1cf66d03f08617919c9627cc4cc0e65ae13
3
+ size 203244197