timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
e9188c4
1 Parent(s): 8b0034d
Files changed (4) hide show
  1. README.md +148 -0
  2. config.json +36 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 inception_v3.tf_adv_in1k
11
+
12
+ A Inception-v3 image classification model. Adversarially trained on ImageNet-1k by paper authors. Ported from Tensorflow by Ross Wightman.
13
+
14
+ ## Model Details
15
+ - **Model Type:** Image classification / feature backbone
16
+ - **Model Stats:**
17
+ - Params (M): 23.8
18
+ - GMACs: 5.7
19
+ - Activations (M): 9.0
20
+ - Image size: 299 x 299
21
+ - **Papers:**
22
+ - Rethinking the Inception Architecture for Computer Vision: https://arxiv.org/abs/1512.00567
23
+ - Adversarial Attacks and Defences Competition: https://arxiv.org/abs/1804.00097
24
+ - **Original:** https://github.com/tensorflow/models
25
+ - **Dataset:** ImageNet-1k
26
+
27
+ ## Model Usage
28
+ ### Image Classification
29
+ ```python
30
+ from urllib.request import urlopen
31
+ from PIL import Image
32
+ import timm
33
+
34
+ img = Image.open(urlopen(
35
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
36
+ ))
37
+
38
+ model = timm.create_model('inception_v3.tf_adv_in1k', pretrained=True)
39
+ model = model.eval()
40
+
41
+ # get model specific transforms (normalization, resize)
42
+ data_config = timm.data.resolve_model_data_config(model)
43
+ transforms = timm.data.create_transform(**data_config, is_training=False)
44
+
45
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
46
+
47
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
48
+ ```
49
+
50
+ ### Feature Map Extraction
51
+ ```python
52
+ from urllib.request import urlopen
53
+ from PIL import Image
54
+ import timm
55
+
56
+ img = Image.open(urlopen(
57
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
58
+ ))
59
+
60
+ model = timm.create_model(
61
+ 'inception_v3.tf_adv_in1k',
62
+ pretrained=True,
63
+ features_only=True,
64
+ )
65
+ model = model.eval()
66
+
67
+ # get model specific transforms (normalization, resize)
68
+ data_config = timm.data.resolve_model_data_config(model)
69
+ transforms = timm.data.create_transform(**data_config, is_training=False)
70
+
71
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
72
+
73
+ for o in output:
74
+ # print shape of each feature map in output
75
+ # e.g.:
76
+ # torch.Size([1, 64, 147, 147])
77
+ # torch.Size([1, 192, 71, 71])
78
+ # torch.Size([1, 288, 35, 35])
79
+ # torch.Size([1, 768, 17, 17])
80
+ # torch.Size([1, 2048, 8, 8])
81
+
82
+ print(o.shape)
83
+ ```
84
+
85
+ ### Image Embeddings
86
+ ```python
87
+ from urllib.request import urlopen
88
+ from PIL import Image
89
+ import timm
90
+
91
+ img = Image.open(urlopen(
92
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
93
+ ))
94
+
95
+ model = timm.create_model(
96
+ 'inception_v3.tf_adv_in1k',
97
+ pretrained=True,
98
+ num_classes=0, # remove classifier nn.Linear
99
+ )
100
+ model = model.eval()
101
+
102
+ # get model specific transforms (normalization, resize)
103
+ data_config = timm.data.resolve_model_data_config(model)
104
+ transforms = timm.data.create_transform(**data_config, is_training=False)
105
+
106
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
107
+
108
+ # or equivalently (without needing to set num_classes=0)
109
+
110
+ output = model.forward_features(transforms(img).unsqueeze(0))
111
+ # output is unpooled, a (1, 2048, 8, 8) shaped tensor
112
+
113
+ output = model.forward_head(output, pre_logits=True)
114
+ # output is a (1, num_features) shaped tensor
115
+ ```
116
+
117
+ ## Model Comparison
118
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
119
+
120
+ ## Citation
121
+ ```bibtex
122
+ @article{DBLP:journals/corr/SzegedyVISW15,
123
+ author = {Christian Szegedy and
124
+ Vincent Vanhoucke and
125
+ Sergey Ioffe and
126
+ Jonathon Shlens and
127
+ Zbigniew Wojna},
128
+ title = {Rethinking the Inception Architecture for Computer Vision},
129
+ journal = {CoRR},
130
+ volume = {abs/1512.00567},
131
+ year = {2015},
132
+ url = {http://arxiv.org/abs/1512.00567},
133
+ archivePrefix = {arXiv},
134
+ eprint = {1512.00567},
135
+ timestamp = {Mon, 13 Aug 2018 16:49:07 +0200},
136
+ biburl = {https://dblp.org/rec/journals/corr/SzegedyVISW15.bib},
137
+ bibsource = {dblp computer science bibliography, https://dblp.org}
138
+ }
139
+ ```
140
+ ```bibtex
141
+ @article{Kurakin2018AdversarialAA,
142
+ title={Adversarial Attacks and Defences Competition},
143
+ author={Alexey Kurakin and Ian J. Goodfellow and Samy Bengio and Yinpeng Dong and Fangzhou Liao and Ming Liang and Tianyu Pang and Jun Zhu and Xiaolin Hu and Cihang Xie and Jianyu Wang and Zhishuai Zhang and Zhou Ren and Alan Loddon Yuille and Sangxia Huang and Yao Zhao and Yuzhe Zhao and Zhonglin Han and Junjiajia Long and Yerkebulan Berdibekov and Takuya Akiba and Seiya Tokui and Motoki Abe},
144
+ journal={ArXiv},
145
+ year={2018},
146
+ volume={abs/1804.00097}
147
+ }
148
+ ```
config.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "inception_v3",
3
+ "num_classes": 1000,
4
+ "num_features": 2048,
5
+ "pretrained_cfg": {
6
+ "tag": "tf_adv_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.875,
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
+ "label_offset": 1,
29
+ "pool_size": [
30
+ 8,
31
+ 8
32
+ ],
33
+ "first_conv": "Conv2d_1a_3x3.conv",
34
+ "classifier": "fc"
35
+ }
36
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:65f7c75ec076db9b4a0c2c3df6145c5936718701c23520c4075a018bd47edbbb
3
+ size 95533832
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bc3a57040446a90138598ca27ea14b506b5294db3ccf66b5fe9e20384c129e9e
3
+ size 95677029