timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
8046f7b
1 Parent(s): a875fe8

Update model config and README

Browse files
Files changed (2) hide show
  1. README.md +140 -2
  2. model.safetensors +3 -0
README.md CHANGED
@@ -2,6 +2,144 @@
2
  tags:
3
  - image-classification
4
  - timm
5
- library_tag: timm
 
 
 
6
  ---
7
- # Model card for mobilenetv3_small_075.lamb_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 mobilenetv3_small_075.lamb_in1k
11
+
12
+ A MobileNet-v3 image classification model. Trained on ImageNet-1k in `timm` using recipe template described below.
13
+
14
+ Recipe details:
15
+ * A LAMB optimizer recipe that is similar to [ResNet Strikes Back](https://arxiv.org/abs/2110.00476) `A2` but 50% longer with EMA weight averaging, no CutMix
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): 2.0
24
+ - GMACs: 0.0
25
+ - Activations (M): 1.3
26
+ - Image size: 224 x 224
27
+ - **Papers:**
28
+ - Searching for MobileNetV3: https://arxiv.org/abs/1905.02244
29
+ - **Dataset:** ImageNet-1k
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('mobilenetv3_small_075.lamb_in1k', 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
+ 'mobilenetv3_small_075.lamb_in1k',
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, 16, 112, 112])
82
+ # torch.Size([1, 16, 56, 56])
83
+ # torch.Size([1, 24, 28, 28])
84
+ # torch.Size([1, 40, 14, 14])
85
+ # torch.Size([1, 432, 7, 7])
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
+ 'mobilenetv3_small_075.lamb_in1k',
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, 432, 7, 7) 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{howard2019searching,
139
+ title={Searching for mobilenetv3},
140
+ author={Howard, Andrew and Sandler, Mark and Chu, Grace and Chen, Liang-Chieh and Chen, Bo and Tan, Mingxing and Wang, Weijun and Zhu, Yukun and Pang, Ruoming and Vasudevan, Vijay and others},
141
+ booktitle={Proceedings of the IEEE/CVF international conference on computer vision},
142
+ pages={1314--1324},
143
+ year={2019}
144
+ }
145
+ ```
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c56c9ffc148d94301a477d5678e6802d0251b22ff23376c396eacd737edad0b7
3
+ size 8228186