timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
ae9e137
1 Parent(s): 5fe033e
Files changed (4) hide show
  1. README.md +143 -0
  2. config.json +35 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 xception65.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
+ ## Model Details
15
+ - **Model Type:** Image classification / feature backbone
16
+ - **Model Stats:**
17
+ - Params (M): 39.9
18
+ - GMACs: 14.0
19
+ - Activations (M): 52.5
20
+ - Image size: 299 x 299
21
+ - **Papers:**
22
+ - Encoder-Decoder with Atrous Separable Convolution for Semantic Image Segmentation: https://arxiv.org/abs/1802.02611
23
+ - Xception: Deep Learning with Depthwise Separable Convolutions: https://arxiv.org/abs/1610.02357
24
+ - ResNet strikes back: An improved training procedure in timm: https://arxiv.org/abs/2110.00476
25
+ - **Dataset:** ImageNet-1k
26
+ - **Original:** https://github.com/huggingface/pytorch-image-models
27
+
28
+ ## Model Usage
29
+ ### Image Classification
30
+ ```python
31
+ from urllib.request import urlopen
32
+ from PIL import Image
33
+ import timm
34
+
35
+ img = Image.open(urlopen(
36
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
37
+ ))
38
+
39
+ model = timm.create_model('xception65.ra3_in1k', pretrained=True)
40
+ model = model.eval()
41
+
42
+ # get model specific transforms (normalization, resize)
43
+ data_config = timm.data.resolve_model_data_config(model)
44
+ transforms = timm.data.create_transform(**data_config, is_training=False)
45
+
46
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
47
+
48
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
49
+ ```
50
+
51
+ ### Feature Map Extraction
52
+ ```python
53
+ from urllib.request import urlopen
54
+ from PIL import Image
55
+ import timm
56
+
57
+ img = Image.open(urlopen(
58
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
59
+ ))
60
+
61
+ model = timm.create_model(
62
+ 'xception65.ra3_in1k',
63
+ pretrained=True,
64
+ features_only=True,
65
+ )
66
+ model = model.eval()
67
+
68
+ # get model specific transforms (normalization, resize)
69
+ data_config = timm.data.resolve_model_data_config(model)
70
+ transforms = timm.data.create_transform(**data_config, is_training=False)
71
+
72
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
73
+
74
+ for o in output:
75
+ # print shape of each feature map in output
76
+ # e.g.:
77
+ # torch.Size([1, 128, 150, 150])
78
+ # torch.Size([1, 256, 75, 75])
79
+ # torch.Size([1, 728, 38, 38])
80
+ # torch.Size([1, 1024, 19, 19])
81
+ # torch.Size([1, 2048, 10, 10])
82
+
83
+ print(o.shape)
84
+ ```
85
+
86
+ ### Image Embeddings
87
+ ```python
88
+ from urllib.request import urlopen
89
+ from PIL import Image
90
+ import timm
91
+
92
+ img = Image.open(urlopen(
93
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
94
+ ))
95
+
96
+ model = timm.create_model(
97
+ 'xception65.ra3_in1k',
98
+ pretrained=True,
99
+ num_classes=0, # remove classifier nn.Linear
100
+ )
101
+ model = model.eval()
102
+
103
+ # get model specific transforms (normalization, resize)
104
+ data_config = timm.data.resolve_model_data_config(model)
105
+ transforms = timm.data.create_transform(**data_config, is_training=False)
106
+
107
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
108
+
109
+ # or equivalently (without needing to set num_classes=0)
110
+
111
+ output = model.forward_features(transforms(img).unsqueeze(0))
112
+ # output is unpooled, a (1, 2048, 10, 10) shaped tensor
113
+
114
+ output = model.forward_head(output, pre_logits=True)
115
+ # output is a (1, num_features) shaped tensor
116
+ ```
117
+
118
+ ## Citation
119
+ ```bibtex
120
+ @inproceedings{deeplabv3plus2018,
121
+ title={Encoder-Decoder with Atrous Separable Convolution for Semantic Image Segmentation},
122
+ author={Liang-Chieh Chen and Yukun Zhu and George Papandreou and Florian Schroff and Hartwig Adam},
123
+ booktitle={ECCV},
124
+ year={2018}
125
+ }
126
+ ```
127
+ ```bibtex
128
+ @misc{chollet2017xception,
129
+ title={Xception: Deep Learning with Depthwise Separable Convolutions},
130
+ author={François Chollet},
131
+ year={2017},
132
+ eprint={1610.02357},
133
+ archivePrefix={arXiv},
134
+ primaryClass={cs.CV}
135
+ }
136
+ ```
137
+ ```bibtex
138
+ @inproceedings{wightman2021resnet,
139
+ title={ResNet strikes back: An improved training procedure in timm},
140
+ author={Wightman, Ross and Touvron, Hugo and Jegou, Herve},
141
+ booktitle={NeurIPS 2021 Workshop on ImageNet: Past, Present, and Future}
142
+ }
143
+ ```
config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "xception65",
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:9c42745856a4b9fa3e7baca3cd2c752a89f6a4edf5babc20b64021c798fd1c29
3
+ size 160489744
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5d4fab5d32d8f4c577d1dc113d362edddd315c36f7893e34e29332e97d58262d
3
+ size 160670133