timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
196e479
1 Parent(s): e266697
Files changed (4) hide show
  1. README.md +134 -0
  2. config.json +41 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_name: timm
6
+ license: apache-2.0
7
+ datasets:
8
+ - imagenet-1k
9
+ ---
10
+ # Model card for densenetblur121d.ra_in1k
11
+
12
+ A DenseNet image classification model. Pretrained on ImageNet-1k in `timm` by Ross Wightman using RandAugment `RA` recipe. Related to `B` recipe in [ResNet Strikes Back](https://arxiv.org/abs/2110.00476).
13
+
14
+ This model uses [Blur Pooling](https://arxiv.org/abs/1904.11486).
15
+
16
+ ## Model Details
17
+ - **Model Type:** Image classification / feature backbone
18
+ - **Model Stats:**
19
+ - Params (M): 8.0
20
+ - GMACs: 3.1
21
+ - Activations (M): 7.9
22
+ - Image size: train = 224 x 224, test = 288 x 288
23
+ - **Papers:**
24
+ - Densely Connected Convolutional Networks: https://arxiv.org/abs/1608.06993
25
+ - ResNet strikes back: An improved training procedure in timm: https://arxiv.org/abs/2110.00476
26
+ - **Dataset:** ImageNet-1k
27
+ - **Original:** https://github.com/huggingface/pytorch-image-models
28
+
29
+ ## Model Usage
30
+ ### Image Classification
31
+ ```python
32
+ from urllib.request import urlopen
33
+ from PIL import Image
34
+ import timm
35
+
36
+ img = Image.open(urlopen(
37
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
38
+ ))
39
+
40
+ model = timm.create_model('densenetblur121d.ra_in1k', pretrained=True)
41
+ model = model.eval()
42
+
43
+ # get model specific transforms (normalization, resize)
44
+ data_config = timm.data.resolve_model_data_config(model)
45
+ transforms = timm.data.create_transform(**data_config, is_training=False)
46
+
47
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
48
+
49
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
50
+ ```
51
+
52
+ ### Feature Map Extraction
53
+ ```python
54
+ from urllib.request import urlopen
55
+ from PIL import Image
56
+ import timm
57
+
58
+ img = Image.open(urlopen(
59
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
60
+ ))
61
+
62
+ model = timm.create_model(
63
+ 'densenetblur121d.ra_in1k',
64
+ pretrained=True,
65
+ features_only=True,
66
+ )
67
+ model = model.eval()
68
+
69
+ # get model specific transforms (normalization, resize)
70
+ data_config = timm.data.resolve_model_data_config(model)
71
+ transforms = timm.data.create_transform(**data_config, is_training=False)
72
+
73
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
74
+
75
+ for o in output:
76
+ # print shape of each feature map in output
77
+ # e.g.:
78
+ # torch.Size([1, 64, 112, 112])
79
+ # torch.Size([1, 256, 56, 56])
80
+ # torch.Size([1, 512, 28, 28])
81
+ # torch.Size([1, 1024, 14, 14])
82
+ # torch.Size([1, 1024, 7, 7])
83
+
84
+ print(o.shape)
85
+ ```
86
+
87
+ ### Image Embeddings
88
+ ```python
89
+ from urllib.request import urlopen
90
+ from PIL import Image
91
+ import timm
92
+
93
+ img = Image.open(urlopen(
94
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
95
+ ))
96
+
97
+ model = timm.create_model(
98
+ 'densenetblur121d.ra_in1k',
99
+ pretrained=True,
100
+ num_classes=0, # remove classifier nn.Linear
101
+ )
102
+ model = model.eval()
103
+
104
+ # get model specific transforms (normalization, resize)
105
+ data_config = timm.data.resolve_model_data_config(model)
106
+ transforms = timm.data.create_transform(**data_config, is_training=False)
107
+
108
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
109
+
110
+ # or equivalently (without needing to set num_classes=0)
111
+
112
+ output = model.forward_features(transforms(img).unsqueeze(0))
113
+ # output is unpooled, a (1, 1024, 7, 7) shaped tensor
114
+
115
+ output = model.forward_head(output, pre_logits=True)
116
+ # output is a (1, num_features) shaped tensor
117
+ ```
118
+
119
+ ## Citation
120
+ ```bibtex
121
+ @inproceedings{huang2017densely,
122
+ title={Densely Connected Convolutional Networks},
123
+ author={Huang, Gao and Liu, Zhuang and van der Maaten, Laurens and Weinberger, Kilian Q },
124
+ booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},
125
+ year={2017}
126
+ }
127
+ ```
128
+ ```bibtex
129
+ @inproceedings{wightman2021resnet,
130
+ title={ResNet strikes back: An improved training procedure in timm},
131
+ author={Wightman, Ross and Touvron, Hugo and Jegou, Herve},
132
+ booktitle={NeurIPS 2021 Workshop on ImageNet: Past, Present, and Future}
133
+ }
134
+ ```
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "densenetblur121d",
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
+ 224,
11
+ 224
12
+ ],
13
+ "test_input_size": [
14
+ 3,
15
+ 288,
16
+ 288
17
+ ],
18
+ "fixed_input_size": false,
19
+ "interpolation": "bicubic",
20
+ "crop_pct": 0.875,
21
+ "test_crop_pct": 0.95,
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
+ 7,
36
+ 7
37
+ ],
38
+ "first_conv": "features.conv0",
39
+ "classifier": "classifier"
40
+ }
41
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4716c50991d45c514a6520877e77f3d795694a134fffd6785654240b559e6ca8
3
+ size 32412998
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1e390f3157ddb2ba4d9c2963cea76e6b858623ab951a01d64dec3f480f70aca6
3
+ size 32603993