timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
e2c374d
1 Parent(s): 3917aff
Files changed (4) hide show
  1. README.md +124 -0
  2. config.json +42 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_name: timm
6
+ license: mit
7
+ datasets:
8
+ - imagenet-1k
9
+ ---
10
+ # Model card for edgenext_x_small.in1k
11
+
12
+ An EdgeNeXt image classification model. Trained on ImageNet-1k by paper authors.
13
+
14
+ ## Model Details
15
+ - **Model Type:** Image classification / feature backbone
16
+ - **Model Stats:**
17
+ - Params (M): 2.3
18
+ - GMACs: 0.5
19
+ - Activations (M): 5.9
20
+ - Image size: train = 256 x 256, test = 288 x 288
21
+ - **Papers:**
22
+ - EdgeNeXt: Efficiently Amalgamated CNN-Transformer Architecture for Mobile Vision Applications: https://arxiv.org/abs/2206.10589
23
+ - **Dataset:** ImageNet-1k
24
+ - **Original:** https://github.com/mmaaz60/EdgeNeXt
25
+
26
+ ## Model Usage
27
+ ### Image Classification
28
+ ```python
29
+ from urllib.request import urlopen
30
+ from PIL import Image
31
+ import timm
32
+
33
+ img = Image.open(urlopen(
34
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
35
+ ))
36
+
37
+ model = timm.create_model('edgenext_x_small.in1k', pretrained=True)
38
+ model = model.eval()
39
+
40
+ # get model specific transforms (normalization, resize)
41
+ data_config = timm.data.resolve_model_data_config(model)
42
+ transforms = timm.data.create_transform(**data_config, is_training=False)
43
+
44
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
45
+
46
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
47
+ ```
48
+
49
+ ### Feature Map Extraction
50
+ ```python
51
+ from urllib.request import urlopen
52
+ from PIL import Image
53
+ import timm
54
+
55
+ img = Image.open(urlopen(
56
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
57
+ ))
58
+
59
+ model = timm.create_model(
60
+ 'edgenext_x_small.in1k',
61
+ pretrained=True,
62
+ features_only=True,
63
+ )
64
+ model = model.eval()
65
+
66
+ # get model specific transforms (normalization, resize)
67
+ data_config = timm.data.resolve_model_data_config(model)
68
+ transforms = timm.data.create_transform(**data_config, is_training=False)
69
+
70
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
71
+
72
+ for o in output:
73
+ # print shape of each feature map in output
74
+ # e.g.:
75
+ # torch.Size([1, 32, 64, 64])
76
+ # torch.Size([1, 64, 32, 32])
77
+ # torch.Size([1, 100, 16, 16])
78
+ # torch.Size([1, 192, 8, 8])
79
+
80
+ print(o.shape)
81
+ ```
82
+
83
+ ### Image Embeddings
84
+ ```python
85
+ from urllib.request import urlopen
86
+ from PIL import Image
87
+ import timm
88
+
89
+ img = Image.open(urlopen(
90
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
91
+ ))
92
+
93
+ model = timm.create_model(
94
+ 'edgenext_x_small.in1k',
95
+ pretrained=True,
96
+ num_classes=0, # remove classifier nn.Linear
97
+ )
98
+ model = model.eval()
99
+
100
+ # get model specific transforms (normalization, resize)
101
+ data_config = timm.data.resolve_model_data_config(model)
102
+ transforms = timm.data.create_transform(**data_config, is_training=False)
103
+
104
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
105
+
106
+ # or equivalently (without needing to set num_classes=0)
107
+
108
+ output = model.forward_features(transforms(img).unsqueeze(0))
109
+ # output is unpooled, a (1, 192, 8, 8) shaped tensor
110
+
111
+ output = model.forward_head(output, pre_logits=True)
112
+ # output is a (1, num_features) shaped tensor
113
+ ```
114
+
115
+ ## Citation
116
+ ```bibtex
117
+ @inproceedings{Maaz2022EdgeNeXt,
118
+ title={EdgeNeXt: Efficiently Amalgamated CNN-Transformer Architecture for Mobile Vision Applications},
119
+ author={Muhammad Maaz and Abdelrahman Shaker and Hisham Cholakkal and Salman Khan and Syed Waqas Zamir and Rao Muhammad Anwer and Fahad Shahbaz Khan},
120
+ booktitle={International Workshop on Computational Aspects of Deep Learning at 17th European Conference on Computer Vision (CADL2022)},
121
+ year={2022},
122
+ organization={Springer}
123
+ }
124
+ ```
config.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "edgenext_x_small",
3
+ "num_classes": 1000,
4
+ "num_features": 192,
5
+ "global_pool": "avg",
6
+ "pretrained_cfg": {
7
+ "tag": "in1k",
8
+ "custom_load": false,
9
+ "input_size": [
10
+ 3,
11
+ 256,
12
+ 256
13
+ ],
14
+ "test_input_size": [
15
+ 3,
16
+ 288,
17
+ 288
18
+ ],
19
+ "fixed_input_size": false,
20
+ "interpolation": "bicubic",
21
+ "crop_pct": 0.9,
22
+ "test_crop_pct": 1.0,
23
+ "crop_mode": "center",
24
+ "mean": [
25
+ 0.485,
26
+ 0.456,
27
+ 0.406
28
+ ],
29
+ "std": [
30
+ 0.229,
31
+ 0.224,
32
+ 0.225
33
+ ],
34
+ "num_classes": 1000,
35
+ "pool_size": [
36
+ 8,
37
+ 8
38
+ ],
39
+ "first_conv": "stem.0",
40
+ "classifier": "head.fc"
41
+ }
42
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:acc97b0fe8f75f4a7fca77b4769550bf35de2755ee743467bf6fffc038fd5837
3
+ size 9367762
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fe65f4364e02b903505ccf371c1babc01e5e66b4830cb8b8b083e4463b27899e
3
+ size 9424229