timm documentation
NaFlex ViT
NaFlex ViT
Category: ViT · Code: timm/models/naflexvit.py · Architectures: 8 · Pretrained weights: 5 (3 with ImageNet-1k results)
A Vision Transformer with the patch embedding and position encoding in one module, supporting pre-patchified inputs with variable aspect ratio and resolution (NaFlex), FlexiViT variable patch size and NaViT factorized position embeddings.
Papers
- An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- FlexiViT: One Model for All Patch Sizes
- Patch n’ Pack: NaViT, a Vision Transformer for any Aspect Ratio and Resolution
- SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Features
Usage
See the Quickstart for loading pretrained weights, image preprocessing and fine-tuning, and Feature Extraction for using the models as backbones.
>>> import timm
>>> model = timm.create_model('naflexvit_base_patch16_parfac_gap.e300_s576_in1k', pretrained=True)
>>> data_config = timm.data.resolve_model_data_config(model)Model API support
✓ supported, ✓ (square) works for square sizes only, ✗ not supported, – not needed (the model already accepts any input
size). Checked by running each feature on a randomly initialized model (NaFlexVit with naflexvit_base_patch16_parfac_gap at 384), other architectures of the same class are expected to behave the same. See
the Model API page for details.
Architectures
| Architecture | Params (M) | GMACs | Input size | Pretrained weights |
|---|---|---|---|---|
naflexvit_base_patch16_gap | 86.63 | 55.86 | 384 | 1 |
naflexvit_base_patch16_map | 93.72 | 56.23 | 384 | 0 |
naflexvit_base_patch16_par_gap | 86.63 | 55.86 | 384 | 1 |
naflexvit_base_patch16_parfac_gap | 86.46 | 55.86 | 384 | 1 |
naflexvit_base_patch16_siglip | 92.93 | 56.12 | 384 | 1 |
naflexvit_so150m2_patch16_reg1_gap | 136.06 | 89.53 | 384 | 0 |
naflexvit_so150m2_patch16_reg1_map | 142.46 | 90.33 | 384 | 0 |
naflexvit_so400m_patch16_siglip | 427.89 | 259.65 | 384 | 1 |
GMACs and parameter counts are for the default input size and classifier of each architecture, from the benchmark results.
Pretrained weights
Top-1 is ImageNet-1k validation accuracy from results-imagenet.csv at
the listed eval size, - if the weight has no ImageNet-1k result (e.g. pretraining or image-text weights). Classes is the
size of the pretrained classifier, none for weights without one.
| Weight | Input size | Top-1 (%) | Eval size | Classes | License | Hub |
|---|---|---|---|---|---|---|
naflexvit_base_patch16_gap.e300_s576_in1k | 384 | 83.340 | 384 | 1000 | apache-2.0 | timm |
naflexvit_base_patch16_par_gap.e300_s576_in1k | 384 | 83.508 | 384 | 1000 | apache-2.0 | timm |
naflexvit_base_patch16_parfac_gap.e300_s576_in1k | 384 | 83.468 | 384 | 1000 | apache-2.0 | timm |
naflexvit_base_patch16_siglip.v2_webli | 384 | - | - | none | apache-2.0 | timm |
naflexvit_so400m_patch16_siglip.v2_webli | 384 | - | - | none | apache-2.0 | timm |