Views
No views yet
train.py --data-dir /data/imagenet/ --amp --amp-dtype bfloat16 --model <name> --naflex-loader -b 64 --opt nadamw --lr 3e-4 --warmup-lr 0 --sched-on-updates --aa rand-m8-inc1-mstd1.0 --weight-decay .1 --grayscale-prob .1 --drop-path 0.2 --reprob 0 --mixup 0.8 --cutmix 1.0 --remode pixel -j 81from 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('naflexvit_base_patch16_parfac_gap.e300_s576_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 'naflexvit_base_patch16_parfac_gap.e300_s576_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, 24, 24])
26 # torch.Size([1, 768, 24, 24])
27 # torch.Size([1, 768, 24, 24])
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 'naflexvit_base_patch16_parfac_gap.e300_s576_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, 580, 768) shaped tensor
26
27output = model.forward_head(output, pre_logits=True)
28# output is a (1, num_features) shaped tensor| Model | Top-1 Acc | Top-5 Acc | Params (M) | Eval Seq Len |
|---|---|---|---|---|
| naflexvit_base_patch16_par_gap.e300_s576_in1k | 83.67 | 96.45 | 86.63 | 576 |
| naflexvit_base_patch16_parfac_gap.e300_s576_in1k | 83.63 | 96.41 | 86.46 | 576 |
| naflexvit_base_patch16_gap.e300_s576_in1k | 83.50 | 96.46 | 86.63 | 576 |
1@misc{rw2019timm,
2 author = {Ross Wightman},
3 title = {PyTorch Image Models},
4 year = {2019},
5 publisher = {GitHub},
6 journal = {GitHub repository},
7 doi = {10.5281/zenodo.4414861},
8 howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
9}1@article{tschannen2025siglip,
2 title={Siglip 2: Multilingual vision-language encoders with improved semantic understanding, localization, and dense features},
3 author={Tschannen, Michael and Gritsenko, Alexey and Wang, Xiao and Naeem, Muhammad Ferjad and Alabdulmohsin, Ibrahim and Parthasarathy, Nikhil and Evans, Talfan and Beyer, Lucas and Xia, Ye and Mustafa, Basil and others},
4 journal={arXiv preprint arXiv:2502.14786},
5 year={2025}
6}1@article{dehghani2023navit,
2 title={Patch n' Pack: NaViT, a Vision Transformer for any Aspect Ratio and Resolution},
3 author={Dehghani, Mostafa and Mustafa, Basil and Djolonga, Josip and Heek, Jonathan and Minderer, Matthias and Caron, Mathilde and Steiner, Andreas and Puigcerver, Joan and Geirhos, Robert and Alabdulmohsin, Ibrahim and others},
4 journal={arXiv preprint arXiv:2307.06304},
5 year={2023}
6}1@article{beyer2022flexivit,
2 title={FlexiViT: One Model for All Patch Sizes},
3 author={Beyer, Lucas and Izmailov, Pavel and Kolesnikov, Alexander and Caron, Mathilde and Kornblith, Simon and Zhai, Xiaohua and Minderer, Matthias and Tschannen, Michael and Alabdulmohsin, Ibrahim and Pavetic, Filip},
4 journal={arXiv preprint arXiv:2212.08013},
5 year={2022}
6}