rwightman HF staff commited on
Commit
6a394ee
1 Parent(s): c9b10c2
Files changed (4) hide show
  1. README.md +152 -0
  2. config.json +41 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_tag: timm
6
+ license: apache-2.0
7
+ ---
8
+ # Model card for darknetaa53.c2ns_in1k
9
+
10
+ A DarkNet 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): 36.0
23
+ - GMACs: 8.0
24
+ - Activations (M): 12.4
25
+ - Image size: train = 256 x 256, test = 288 x 288
26
+ - **Papers:**
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('darknetaa53.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
+ 'darknetaa53.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, 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
+ 'darknetaa53.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, 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{Redmon2018YOLOv3AI,
128
+ title={YOLOv3: An Incremental Improvement},
129
+ author={Joseph Redmon and Ali Farhadi},
130
+ journal={ArXiv},
131
+ year={2018},
132
+ volume={abs/1804.02767}
133
+ }
134
+ ```
135
+ ```bibtex
136
+ @inproceedings{wightman2021resnet,
137
+ title={ResNet strikes back: An improved training procedure in timm},
138
+ author={Wightman, Ross and Touvron, Hugo and Jegou, Herve},
139
+ booktitle={NeurIPS 2021 Workshop on ImageNet: Past, Present, and Future}
140
+ }
141
+ ```
142
+ ```bibtex
143
+ @misc{rw2019timm,
144
+ author = {Ross Wightman},
145
+ title = {PyTorch Image Models},
146
+ year = {2019},
147
+ publisher = {GitHub},
148
+ journal = {GitHub repository},
149
+ doi = {10.5281/zenodo.4414861},
150
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
151
+ }
152
+ ```
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "darknetaa53",
3
+ "num_classes": 1000,
4
+ "num_features": 1024,
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": "bilinear",
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:3d920e9804ce081e7a9d5c74df3f8caf02b84486b0b450405560ed3d3fd27a61
3
+ size 144267562
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3bbe7c1976d03534ba827e40c07b611d1ba6d6a9d82d466dd32809211185fecb
3
+ size 144351413