Views
No views yet
1from urllib.request import urlopen
2from PIL import Image
3import timm
4
5img = Image.open(urlopen(
6 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
7))
8
9model = timm.create_model('vit_base_patch16_rope_224.naver_in1k', pretrained=True)
10model = model.eval()
11
12# get model specific transforms (normalization, resize)
13data_config = timm.data.resolve_model_data_config(model)
14transforms = timm.data.create_transform(**data_config, is_training=False)
15
16output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
17
18top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)1from urllib.request import urlopen
2from PIL import Image
3import timm
4
5img = Image.open(urlopen(
6 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
7))
8
9model = timm.create_model(
10 'vit_base_patch16_rope_224.naver_in1k',
11 pretrained=True,
12 features_only=True,
13)
14model = model.eval()
15
16# get model specific transforms (normalization, resize)
17data_config = timm.data.resolve_model_data_config(model)
18transforms = timm.data.create_transform(**data_config, is_training=False)
19
20output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
21
22for o in output:
23 # print shape of each feature map in output
24 # e.g.:
25 # torch.Size([1, 768, 14, 14])
26 # torch.Size([1, 768, 14, 14])
27 # torch.Size([1, 768, 14, 14])
28
29 print(o.shape)1from urllib.request import urlopen
2from PIL import Image
3import timm
4
5img = Image.open(urlopen(
6 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
7))
8
9model = timm.create_model(
10 'vit_base_patch16_rope_224.naver_in1k',
11 pretrained=True,
12 num_classes=0, # remove classifier nn.Linear
13)
14model = model.eval()
15
16# get model specific transforms (normalization, resize)
17data_config = timm.data.resolve_model_data_config(model)
18transforms = timm.data.create_transform(**data_config, is_training=False)
19
20output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
21
22# or equivalently (without needing to set num_classes=0)
23
24output = model.forward_features(transforms(img).unsqueeze(0))
25# output is unpooled, a (1, 197, 768) shaped tensor
26
27output = model.forward_head(output, pre_logits=True)
28# output is a (1, num_features) shaped tensor| model | img_size | top1 | top5 | param_count |
|---|---|---|---|---|
| vit_large_patch16_rope_mixed_ape_224.naver_in1k | 224 | 84.84 | 97.122 | 304.4 |
| vit_large_patch16_rope_mixed_224.naver_in1k | 224 | 84.828 | 97.116 | 304.2 |
| vit_large_patch16_rope_ape_224.naver_in1k | 224 | 84.65 | 97.154 | 304.37 |
| vit_large_patch16_rope_224.naver_in1k | 224 | 84.648 | 97.122 | 304.17 |
| vit_base_patch16_rope_mixed_ape_224.naver_in1k | 224 | 83.894 | 96.754 | 86.59 |
| vit_base_patch16_rope_mixed_224.naver_in1k | 224 | 83.804 | 96.712 | 86.44 |
| vit_base_patch16_rope_ape_224.naver_in1k | 224 | 83.782 | 96.61 | 86.59 |
| vit_base_patch16_rope_224.naver_in1k | 224 | 83.718 | 96.672 | 86.43 |
| vit_small_patch16_rope_224.naver_in1k | 224 | 81.23 | 95.022 | 21.98 |
| vit_small_patch16_rope_mixed_224.naver_in1k | 224 | 81.216 | 95.022 | 21.99 |
| vit_small_patch16_rope_ape_224.naver_in1k | 224 | 81.004 | 95.016 | 22.06 |
| vit_small_patch16_rope_mixed_ape_224.naver_in1k | 224 | 80.986 | 94.976 | 22.06 |
| model | img_size | top1 | top5 | param_count |
|---|---|---|---|---|
| vit_large_patch16_rope_mixed_224.naver_in1k | 320 | 85.656 | 97.474 | 304.2 |
| vit_large_patch16_rope_mixed_ape_224.naver_in1k | 320 | 85.594 | 97.508 | 304.4 |
| vit_large_patch16_rope_ape_224.naver_in1k | 320 | 85.344 | 97.438 | 304.37 |
| vit_large_patch16_rope_224.naver_in1k | 320 | 85.258 | 97.42 | 304.17 |
| vit_base_patch16_rope_mixed_224.naver_in1k | 320 | 84.65 | 97.106 | 86.44 |
| vit_base_patch16_rope_mixed_ape_224.naver_in1k | 320 | 84.58 | 97.144 | 86.59 |
| vit_base_patch16_rope_ape_224.naver_in1k | 320 | 84.368 | 96.968 | 86.59 |
| vit_base_patch16_rope_224.naver_in1k | 320 | 84.296 | 96.898 | 86.43 |
| vit_small_patch16_rope_mixed_224.naver_in1k | 320 | 82.238 | 95.592 | 21.99 |
| vit_small_patch16_rope_mixed_ape_224.naver_in1k | 320 | 82.056 | 95.586 | 22.06 |
| vit_small_patch16_rope_ape_224.naver_in1k | 320 | 81.944 | 95.506 | 22.06 |
| vit_small_patch16_rope_224.naver_in1k | 320 | 81.46 | 95.142 | 21.98 |
1@inproceedings{heo2024rotary,
2 title={Rotary position embedding for vision transformer},
3 author={Heo, Byeongho and Park, Song and Han, Dongyoon and Yun, Sangdoo},
4 booktitle={European Conference on Computer Vision},
5 pages={289--305},
6 year={2024},
7 organization={Springer}
8}