timm documentation

NaFlex ViT

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v1.0.30).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

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

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

FeatureNaFlexVit
features_only=True feature maps✓ (strides 16, 16, 16)
forward_intermediates()✓
prune_intermediate_layers()✗
Any input size, no changes needed✓
set_input_size()–
dynamic_img_size=True–
set_grad_checkpointing()✓
Layer-wise LR decay (group_matcher())✓
reset_classifier()✓

✓ 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

ArchitectureParams (M)GMACsInput sizePretrained weights
naflexvit_base_patch16_gap86.6355.863841
naflexvit_base_patch16_map93.7256.233840
naflexvit_base_patch16_par_gap86.6355.863841
naflexvit_base_patch16_parfac_gap86.4655.863841
naflexvit_base_patch16_siglip92.9356.123841
naflexvit_so150m2_patch16_reg1_gap136.0689.533840
naflexvit_so150m2_patch16_reg1_map142.4690.333840
naflexvit_so400m_patch16_siglip427.89259.653841

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.

WeightInput sizeTop-1 (%)Eval sizeClassesLicenseHub
naflexvit_base_patch16_gap.e300_s576_in1k38483.3403841000apache-2.0timm
naflexvit_base_patch16_par_gap.e300_s576_in1k38483.5083841000apache-2.0timm
naflexvit_base_patch16_parfac_gap.e300_s576_in1k38483.4683841000apache-2.0timm
naflexvit_base_patch16_siglip.v2_webli384--noneapache-2.0timm
naflexvit_so400m_patch16_siglip.v2_webli384--noneapache-2.0timm
Update on GitHub