timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
327b9de
1 Parent(s): 917d3b0
Files changed (4) hide show
  1. README.md +145 -0
  2. config.json +35 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 xception41p.ra3_in1k
11
+
12
+ An Aligned Xception image classification model. Pretrained on ImageNet-1k in `timm` by Ross Wightman using RandAugment `RA3` recipe. Related to `B` recipe in [ResNet Strikes Back](https://arxiv.org/abs/2110.00476).
13
+
14
+ This Xception variation uses a `timm` specific pre-activation Xception block.
15
+
16
+ ## Model Details
17
+ - **Model Type:** Image classification / feature backbone
18
+ - **Model Stats:**
19
+ - Params (M): 26.9
20
+ - GMACs: 9.2
21
+ - Activations (M): 39.9
22
+ - Image size: 299 x 299
23
+ - **Papers:**
24
+ - Encoder-Decoder with Atrous Separable Convolution for Semantic Image Segmentation: https://arxiv.org/abs/1802.02611
25
+ - Xception: Deep Learning with Depthwise Separable Convolutions: https://arxiv.org/abs/1610.02357
26
+ - ResNet strikes back: An improved training procedure in timm: https://arxiv.org/abs/2110.00476
27
+ - **Dataset:** ImageNet-1k
28
+ - **Original:** https://github.com/huggingface/pytorch-image-models
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('xception41p.ra3_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
+ 'xception41p.ra3_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, 128, 150, 150])
80
+ # torch.Size([1, 256, 75, 75])
81
+ # torch.Size([1, 728, 38, 38])
82
+ # torch.Size([1, 1024, 19, 19])
83
+ # torch.Size([1, 2048, 10, 10])
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
+ 'xception41p.ra3_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, 2048, 10, 10) shaped tensor
115
+
116
+ output = model.forward_head(output, pre_logits=True)
117
+ # output is a (1, num_features) shaped tensor
118
+ ```
119
+
120
+ ## Citation
121
+ ```bibtex
122
+ @inproceedings{deeplabv3plus2018,
123
+ title={Encoder-Decoder with Atrous Separable Convolution for Semantic Image Segmentation},
124
+ author={Liang-Chieh Chen and Yukun Zhu and George Papandreou and Florian Schroff and Hartwig Adam},
125
+ booktitle={ECCV},
126
+ year={2018}
127
+ }
128
+ ```
129
+ ```bibtex
130
+ @misc{chollet2017xception,
131
+ title={Xception: Deep Learning with Depthwise Separable Convolutions},
132
+ author={François Chollet},
133
+ year={2017},
134
+ eprint={1610.02357},
135
+ archivePrefix={arXiv},
136
+ primaryClass={cs.CV}
137
+ }
138
+ ```
139
+ ```bibtex
140
+ @inproceedings{wightman2021resnet,
141
+ title={ResNet strikes back: An improved training procedure in timm},
142
+ author={Wightman, Ross and Touvron, Hugo and Jegou, Herve},
143
+ booktitle={NeurIPS 2021 Workshop on ImageNet: Past, Present, and Future}
144
+ }
145
+ ```
config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "xception41p",
3
+ "num_classes": 1000,
4
+ "num_features": 2048,
5
+ "pretrained_cfg": {
6
+ "tag": "ra3_in1k",
7
+ "custom_load": false,
8
+ "input_size": [
9
+ 3,
10
+ 299,
11
+ 299
12
+ ],
13
+ "fixed_input_size": false,
14
+ "interpolation": "bicubic",
15
+ "crop_pct": 0.94,
16
+ "crop_mode": "center",
17
+ "mean": [
18
+ 0.5,
19
+ 0.5,
20
+ 0.5
21
+ ],
22
+ "std": [
23
+ 0.5,
24
+ 0.5,
25
+ 0.5
26
+ ],
27
+ "num_classes": 1000,
28
+ "pool_size": [
29
+ 10,
30
+ 10
31
+ ],
32
+ "first_conv": "stem.0.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:84cc7268d4d0973769ac78db2c1d07e5bbfbcab2447d6f1df3f7b755ba7b2dea
3
+ size 107874034
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0ff7c650d7410ae7a2ea785955b49f943b05020626a750a6a204581f95977a5c
3
+ size 107944325