rwightman HF staff commited on
Commit
7226ab1
1 Parent(s): 6bbc0a6
Files changed (4) hide show
  1. README.md +143 -0
  2. config.json +35 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 nextvit_base.bd_in1k_384
11
+
12
+ A Next-ViT image classification model. Trained on ImageNet-1k by paper authors.
13
+
14
+
15
+
16
+ ## Model Details
17
+ - **Model Type:** Image classification / feature backbone
18
+ - **Model Stats:**
19
+ - Params (M): 44.8
20
+ - GMACs: 24.2
21
+ - Activations (M): 66.0
22
+ - Image size: 384 x 384
23
+ - **Dataset:** ImageNet-1k
24
+ - **Papers:**
25
+ - Next-ViT: Next Generation Vision Transformer for Efficient Deployment in Realistic Industrial Scenarios: https://arxiv.org/abs/2207.05501
26
+ - **Original:** https://github.com/bytedance/Next-ViT
27
+
28
+ ## Model Usage
29
+ ### Image Classification
30
+ ```python
31
+ from urllib.request import urlopen
32
+ from PIL import Image
33
+ import timm
34
+
35
+ img = Image.open(urlopen(
36
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
37
+ ))
38
+
39
+ model = timm.create_model('nextvit_base.bd_in1k_384', pretrained=True)
40
+ model = model.eval()
41
+
42
+ # get model specific transforms (normalization, resize)
43
+ data_config = timm.data.resolve_model_data_config(model)
44
+ transforms = timm.data.create_transform(**data_config, is_training=False)
45
+
46
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
47
+
48
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
49
+ ```
50
+
51
+ ### Feature Map Extraction
52
+ ```python
53
+ from urllib.request import urlopen
54
+ from PIL import Image
55
+ import timm
56
+
57
+ img = Image.open(urlopen(
58
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
59
+ ))
60
+
61
+ model = timm.create_model(
62
+ 'nextvit_base.bd_in1k_384',
63
+ pretrained=True,
64
+ features_only=True,
65
+ )
66
+ model = model.eval()
67
+
68
+ # get model specific transforms (normalization, resize)
69
+ data_config = timm.data.resolve_model_data_config(model)
70
+ transforms = timm.data.create_transform(**data_config, is_training=False)
71
+
72
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
73
+
74
+ for o in output:
75
+ # print shape of each feature map in output
76
+ # e.g.:
77
+ # torch.Size([1, 96, 96, 96])
78
+ # torch.Size([1, 256, 48, 48])
79
+ # torch.Size([1, 512, 24, 24])
80
+ # torch.Size([1, 1024, 12, 12])
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
+ 'nextvit_base.bd_in1k_384',
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, 1024, 12, 12) 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
+ ### By Top-1
119
+
120
+ |model |top1 |top1_err|top5 |top5_err|param_count|
121
+ |---------------------------------|------|--------|------|--------|-----------|
122
+ |nextvit_large.bd_ssld_6m_in1k_384|86.542|13.458 |98.142|1.858 |57.87 |
123
+ |nextvit_base.bd_ssld_6m_in1k_384 |86.352|13.648 |98.04 |1.96 |44.82 |
124
+ |nextvit_small.bd_ssld_6m_in1k_384|85.964|14.036 |97.908|2.092 |31.76 |
125
+ |nextvit_large.bd_ssld_6m_in1k |85.48 |14.52 |97.696|2.304 |57.87 |
126
+ |nextvit_base.bd_ssld_6m_in1k |85.186|14.814 |97.59 |2.41 |44.82 |
127
+ |nextvit_large.bd_in1k_384 |84.924|15.076 |97.294|2.706 |57.87 |
128
+ |nextvit_small.bd_ssld_6m_in1k |84.862|15.138 |97.382|2.618 |31.76 |
129
+ |nextvit_base.bd_in1k_384 |84.706|15.294 |97.224|2.776 |44.82 |
130
+ |nextvit_small.bd_in1k_384 |84.022|15.978 |96.99 |3.01 |31.76 |
131
+ |nextvit_large.bd_in1k |83.626|16.374 |96.694|3.306 |57.87 |
132
+ |nextvit_base.bd_in1k |83.472|16.528 |96.656|3.344 |44.82 |
133
+ |nextvit_small.bd_in1k |82.61 |17.39 |96.226|3.774 |31.76 |
134
+
135
+ ## Citation
136
+ ```bibtex
137
+ @article{li2022next,
138
+ title={Next-ViT: Next Generation Vision Transformer for Efficient Deployment in Realistic Industrial Scenarios},
139
+ author={Li, Jiashi and Xia, Xin and Li, Wei and Li, Huixia and Wang, Xing and Xiao, Xuefeng and Wang, Rui and Zheng, Min and Pan, Xin},
140
+ journal={arXiv preprint arXiv:2207.05501},
141
+ year={2022}
142
+ }
143
+ ```
config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "nextvit_base",
3
+ "num_classes": 1000,
4
+ "num_features": 1024,
5
+ "pretrained_cfg": {
6
+ "tag": "bd_in1k_384",
7
+ "custom_load": false,
8
+ "input_size": [
9
+ 3,
10
+ 384,
11
+ 384
12
+ ],
13
+ "fixed_input_size": false,
14
+ "interpolation": "bicubic",
15
+ "crop_pct": 1.0,
16
+ "crop_mode": "center",
17
+ "mean": [
18
+ 0.485,
19
+ 0.456,
20
+ 0.406
21
+ ],
22
+ "std": [
23
+ 0.229,
24
+ 0.224,
25
+ 0.225
26
+ ],
27
+ "num_classes": 1000,
28
+ "pool_size": [
29
+ 12,
30
+ 12
31
+ ],
32
+ "first_conv": "stem.0.conv",
33
+ "classifier": "head.fc"
34
+ }
35
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c4e2aeb5a1771793841102be5c70c8d4e4a43af757be3c158c00757d452fe88
3
+ size 179589280
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e3f9166bbb1c87a8036d7f32aadfa37a7a6490978f574862994edb83e3770e33
3
+ size 179771610