rwightman HF staff commited on
Commit
cbf275c
1 Parent(s): 16d5d4d

Update model config and README

Browse files
Files changed (3) hide show
  1. README.md +141 -2
  2. config.json +1 -0
  3. model.safetensors +3 -0
README.md CHANGED
@@ -2,6 +2,145 @@
2
  tags:
3
  - image-classification
4
  - timm
5
- library_tag: timm
 
 
 
6
  ---
7
- # Model card for efficientnet_b5.in12k
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  tags:
3
  - image-classification
4
  - timm
5
+ library_name: timm
6
+ license: apache-2.0
7
+ datasets:
8
+ - imagenet-12k
9
  ---
10
+ # Model card for efficientnet_b5.sw_in12k
11
+
12
+ A EfficientNet image classification model. Trained on ImageNet-12k by Ross Wightman in `timm` using recipe template described below.
13
+
14
+ Recipe details:
15
+ * Based on Swin Transformer train / pretrain recipe with modifications (related to both DeiT and ConvNeXt recipes)
16
+ * AdamW optimizer, gradient clipping, EMA weight averaging
17
+ * Cosine LR schedule with warmup
18
+
19
+
20
+ ## Model Details
21
+ - **Model Type:** Image classification / feature backbone
22
+ - **Model Stats:**
23
+ - Params (M): 52.6
24
+ - GMACs: 8.3
25
+ - Activations (M): 80.7
26
+ - Image size: 416 x 416
27
+ - **Papers:**
28
+ - EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks: https://arxiv.org/abs/1905.11946
29
+ - **Dataset:** ImageNet-12k
30
+ - **Original:** https://github.com/huggingface/pytorch-image-models
31
+
32
+ ## Model Usage
33
+ ### Image Classification
34
+ ```python
35
+ from urllib.request import urlopen
36
+ from PIL import Image
37
+ import timm
38
+
39
+ img = Image.open(urlopen(
40
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
41
+ ))
42
+
43
+ model = timm.create_model('efficientnet_b5.sw_in12k', pretrained=True)
44
+ model = model.eval()
45
+
46
+ # get model specific transforms (normalization, resize)
47
+ data_config = timm.data.resolve_model_data_config(model)
48
+ transforms = timm.data.create_transform(**data_config, is_training=False)
49
+
50
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
51
+
52
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
53
+ ```
54
+
55
+ ### Feature Map Extraction
56
+ ```python
57
+ from urllib.request import urlopen
58
+ from PIL import Image
59
+ import timm
60
+
61
+ img = Image.open(urlopen(
62
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
63
+ ))
64
+
65
+ model = timm.create_model(
66
+ 'efficientnet_b5.sw_in12k',
67
+ pretrained=True,
68
+ features_only=True,
69
+ )
70
+ model = model.eval()
71
+
72
+ # get model specific transforms (normalization, resize)
73
+ data_config = timm.data.resolve_model_data_config(model)
74
+ transforms = timm.data.create_transform(**data_config, is_training=False)
75
+
76
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
77
+
78
+ for o in output:
79
+ # print shape of each feature map in output
80
+ # e.g.:
81
+ # torch.Size([1, 24, 208, 208])
82
+ # torch.Size([1, 40, 104, 104])
83
+ # torch.Size([1, 64, 52, 52])
84
+ # torch.Size([1, 176, 26, 26])
85
+ # torch.Size([1, 512, 13, 13])
86
+
87
+ print(o.shape)
88
+ ```
89
+
90
+ ### Image Embeddings
91
+ ```python
92
+ from urllib.request import urlopen
93
+ from PIL import Image
94
+ import timm
95
+
96
+ img = Image.open(urlopen(
97
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
98
+ ))
99
+
100
+ model = timm.create_model(
101
+ 'efficientnet_b5.sw_in12k',
102
+ pretrained=True,
103
+ num_classes=0, # remove classifier nn.Linear
104
+ )
105
+ model = model.eval()
106
+
107
+ # get model specific transforms (normalization, resize)
108
+ data_config = timm.data.resolve_model_data_config(model)
109
+ transforms = timm.data.create_transform(**data_config, is_training=False)
110
+
111
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
112
+
113
+ # or equivalently (without needing to set num_classes=0)
114
+
115
+ output = model.forward_features(transforms(img).unsqueeze(0))
116
+ # output is unpooled, a (1, 2048, 13, 13) shaped tensor
117
+
118
+ output = model.forward_head(output, pre_logits=True)
119
+ # output is a (1, num_features) shaped tensor
120
+ ```
121
+
122
+ ## Model Comparison
123
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
124
+
125
+ ## Citation
126
+ ```bibtex
127
+ @misc{rw2019timm,
128
+ author = {Ross Wightman},
129
+ title = {PyTorch Image Models},
130
+ year = {2019},
131
+ publisher = {GitHub},
132
+ journal = {GitHub repository},
133
+ doi = {10.5281/zenodo.4414861},
134
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
135
+ }
136
+ ```
137
+ ```bibtex
138
+ @inproceedings{tan2019efficientnet,
139
+ title={Efficientnet: Rethinking model scaling for convolutional neural networks},
140
+ author={Tan, Mingxing and Le, Quoc},
141
+ booktitle={International conference on machine learning},
142
+ pages={6105--6114},
143
+ year={2019},
144
+ organization={PMLR}
145
+ }
146
+ ```
config.json CHANGED
@@ -3,6 +3,7 @@
3
  "num_classes": 11821,
4
  "num_features": 2048,
5
  "pretrained_cfg": {
 
6
  "custom_load": false,
7
  "input_size": [
8
  3,
 
3
  "num_classes": 11821,
4
  "num_features": 2048,
5
  "pretrained_cfg": {
6
+ "tag": "sw_in12k",
7
  "custom_load": false,
8
  "input_size": [
9
  3,
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bd3a9c1a8e3bba94f9b25cf3b419bd855c85f9b34fb7b5d482b1b55e5258a3e3
3
+ size 211019082