timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
7cb8ea6
1 Parent(s): 2bc6b33
Files changed (4) hide show
  1. README.md +152 -0
  2. config.json +40 -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
+ datasets:
8
+ - imagenet-1k
9
+ ---
10
+ # Model card for dm_nfnet_f0.dm_in1k
11
+
12
+ A NFNet (Normalization Free Network) image classification model. Trained on ImageNet-1k by paper authors.
13
+
14
+ Normalization Free Networks are (pre-activation) ResNet-like models without any normalization layers. Instead of Batch Normalization or alternatives, they use Scaled Weight Standardization and specifically placed scalar gains in residual path and at non-linearities based on signal propagation analysis.
15
+
16
+
17
+ ## Model Details
18
+ - **Model Type:** Image classification / feature backbone
19
+ - **Model Stats:**
20
+ - Params (M): 71.5
21
+ - GMACs: 7.2
22
+ - Activations (M): 10.2
23
+ - Image size: train = 192 x 192, test = 256 x 256
24
+ - **Papers:**
25
+ - High-Performance Large-Scale Image Recognition Without Normalization: https://arxiv.org/abs/2102.06171
26
+ - Characterizing signal propagation to close the performance gap in unnormalized ResNets: https://arxiv.org/abs/2101.08692
27
+ - **Original:** https://github.com/deepmind/deepmind-research/tree/master/nfnets
28
+ - **Dataset:** ImageNet-1k
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('dm_nfnet_f0.dm_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
+ 'dm_nfnet_f0.dm_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, 64, 96, 96])
80
+ # torch.Size([1, 256, 48, 48])
81
+ # torch.Size([1, 512, 24, 24])
82
+ # torch.Size([1, 1536, 12, 12])
83
+ # torch.Size([1, 3072, 6, 6])
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
+ 'dm_nfnet_f0.dm_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, 3072, 6, 6) 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
+
124
+ ## Citation
125
+ ```bibtex
126
+ @article{brock2021high,
127
+ author={Andrew Brock and Soham De and Samuel L. Smith and Karen Simonyan},
128
+ title={High-Performance Large-Scale Image Recognition Without Normalization},
129
+ journal={arXiv preprint arXiv:2102.06171},
130
+ year={2021}
131
+ }
132
+ ```
133
+ ```bibtex
134
+ @inproceedings{brock2021characterizing,
135
+ author={Andrew Brock and Soham De and Samuel L. Smith},
136
+ title={Characterizing signal propagation to close the performance gap in
137
+ unnormalized ResNets},
138
+ booktitle={9th International Conference on Learning Representations, {ICLR}},
139
+ year={2021}
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,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "dm_nfnet_f0",
3
+ "num_classes": 1000,
4
+ "num_features": 3072,
5
+ "pretrained_cfg": {
6
+ "tag": "dm_in1k",
7
+ "custom_load": false,
8
+ "input_size": [
9
+ 3,
10
+ 192,
11
+ 192
12
+ ],
13
+ "test_input_size": [
14
+ 3,
15
+ 256,
16
+ 256
17
+ ],
18
+ "fixed_input_size": false,
19
+ "interpolation": "bicubic",
20
+ "crop_pct": 0.9,
21
+ "crop_mode": "squash",
22
+ "mean": [
23
+ 0.485,
24
+ 0.456,
25
+ 0.406
26
+ ],
27
+ "std": [
28
+ 0.229,
29
+ 0.224,
30
+ 0.225
31
+ ],
32
+ "num_classes": 1000,
33
+ "pool_size": [
34
+ 6,
35
+ 6
36
+ ],
37
+ "first_conv": "stem.conv1",
38
+ "classifier": "head.fc"
39
+ }
40
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5e6596290aa0bce6f2b8569088b6fc6c7c25487a9c99432d356fd6f3caae548d
3
+ size 285979776
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6389dc8736b6d074b6071121b196ff78441dd024ecc8ec0f319245ae4ebe96d3
3
+ size 286038897