timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
6f13127
1 Parent(s): 9ebe957

Update model config and README

Browse files
Files changed (2) hide show
  1. README.md +148 -2
  2. model.safetensors +3 -0
README.md CHANGED
@@ -2,6 +2,152 @@
2
  tags:
3
  - image-classification
4
  - timm
5
- library_tag: timm
 
 
 
6
  ---
7
- # Model card for fbnetv3_g.ra2_in1k
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 fbnetv3_g.ra2_in1k
11
+
12
+ A FBNet-v3 image classification model. Trained on ImageNet-1k in `timm` using recipe template described below.
13
+
14
+ Recipe details:
15
+ * RandAugment `RA2` recipe. Inspired by and evolved from EfficientNet RandAugment recipes. Published as `B` recipe in [ResNet Strikes Back](https://arxiv.org/abs/2110.00476).
16
+ * RMSProp (TF 1.0 behaviour) optimizer, EMA weight averaging
17
+ * Step (exponential decay w/ staircase) LR schedule with warmup
18
+
19
+
20
+ ## Model Details
21
+ - **Model Type:** Image classification / feature backbone
22
+ - **Model Stats:**
23
+ - Params (M): 16.6
24
+ - GMACs: 1.3
25
+ - Activations (M): 14.9
26
+ - Image size: train = 240 x 240, test = 288 x 288
27
+ - **Papers:**
28
+ - FBNetV3: Joint Architecture-Recipe Search using Predictor Pretraining: https://arxiv.org/abs/2006.02049
29
+ - ResNet strikes back: An improved training procedure in timm: https://arxiv.org/abs/2110.00476
30
+ - **Dataset:** ImageNet-1k
31
+ - **Original:** https://github.com/huggingface/pytorch-image-models
32
+
33
+ ## Model Usage
34
+ ### Image Classification
35
+ ```python
36
+ from urllib.request import urlopen
37
+ from PIL import Image
38
+ import timm
39
+
40
+ img = Image.open(urlopen(
41
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
42
+ ))
43
+
44
+ model = timm.create_model('fbnetv3_g.ra2_in1k', pretrained=True)
45
+ model = model.eval()
46
+
47
+ # get model specific transforms (normalization, resize)
48
+ data_config = timm.data.resolve_model_data_config(model)
49
+ transforms = timm.data.create_transform(**data_config, is_training=False)
50
+
51
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
52
+
53
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
54
+ ```
55
+
56
+ ### Feature Map Extraction
57
+ ```python
58
+ from urllib.request import urlopen
59
+ from PIL import Image
60
+ import timm
61
+
62
+ img = Image.open(urlopen(
63
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
64
+ ))
65
+
66
+ model = timm.create_model(
67
+ 'fbnetv3_g.ra2_in1k',
68
+ pretrained=True,
69
+ features_only=True,
70
+ )
71
+ model = model.eval()
72
+
73
+ # get model specific transforms (normalization, resize)
74
+ data_config = timm.data.resolve_model_data_config(model)
75
+ transforms = timm.data.create_transform(**data_config, is_training=False)
76
+
77
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
78
+
79
+ for o in output:
80
+ # print shape of each feature map in output
81
+ # e.g.:
82
+ # torch.Size([1, 24, 120, 120])
83
+ # torch.Size([1, 40, 60, 60])
84
+ # torch.Size([1, 56, 30, 30])
85
+ # torch.Size([1, 160, 15, 15])
86
+ # torch.Size([1, 1728, 8, 8])
87
+
88
+ print(o.shape)
89
+ ```
90
+
91
+ ### Image Embeddings
92
+ ```python
93
+ from urllib.request import urlopen
94
+ from PIL import Image
95
+ import timm
96
+
97
+ img = Image.open(urlopen(
98
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
99
+ ))
100
+
101
+ model = timm.create_model(
102
+ 'fbnetv3_g.ra2_in1k',
103
+ pretrained=True,
104
+ num_classes=0, # remove classifier nn.Linear
105
+ )
106
+ model = model.eval()
107
+
108
+ # get model specific transforms (normalization, resize)
109
+ data_config = timm.data.resolve_model_data_config(model)
110
+ transforms = timm.data.create_transform(**data_config, is_training=False)
111
+
112
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
113
+
114
+ # or equivalently (without needing to set num_classes=0)
115
+
116
+ output = model.forward_features(transforms(img).unsqueeze(0))
117
+ # output is unpooled, a (1, 1728, 8, 8) shaped tensor
118
+
119
+ output = model.forward_head(output, pre_logits=True)
120
+ # output is a (1, num_features) shaped tensor
121
+ ```
122
+
123
+ ## Model Comparison
124
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
125
+
126
+ ## Citation
127
+ ```bibtex
128
+ @inproceedings{dai2021fbnetv3,
129
+ title={Fbnetv3: Joint architecture-recipe search using predictor pretraining},
130
+ author={Dai, Xiaoliang and Wan, Alvin and Zhang, Peizhao and Wu, Bichen and He, Zijian and Wei, Zhen and Chen, Kan and Tian, Yuandong and Yu, Matthew and Vajda, Peter and others},
131
+ booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
132
+ pages={16276--16285},
133
+ year={2021}
134
+ }
135
+ ```
136
+ ```bibtex
137
+ @misc{rw2019timm,
138
+ author = {Ross Wightman},
139
+ title = {PyTorch Image Models},
140
+ year = {2019},
141
+ publisher = {GitHub},
142
+ journal = {GitHub repository},
143
+ doi = {10.5281/zenodo.4414861},
144
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
145
+ }
146
+ ```
147
+ ```bibtex
148
+ @inproceedings{wightman2021resnet,
149
+ title={ResNet strikes back: An improved training procedure in timm},
150
+ author={Wightman, Ross and Touvron, Hugo and Jegou, Herve},
151
+ booktitle={NeurIPS 2021 Workshop on ImageNet: Past, Present, and Future}
152
+ }
153
+ ```
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ebea2401081218e368dbf96d7e0cdceeb662a84d439933c135e6bca79950f61
3
+ size 66927228