# Hiera

**Category:** ViT · **Code:**
[`timm/models/hiera.py`](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/hiera.py) ·
**Architectures:** 8 · **Pretrained weights:** 16 (8 with ImageNet-1k results)

Hiera is a hierarchical vision transformer without specialized modules (convolutions, shifted windows, relative position
biases), relying on masked autoencoder (MAE) pretraining to learn spatial biases.

## Papers

* [Hiera: A Hierarchical Vision Transformer without the Bells-and-Whistles](https://arxiv.org/abs/2306.00989)
* [Window Attention is Bugged: How not to Interpolate Position Embeddings](https://arxiv.org/abs/2311.05613)

## Usage

See the [Quickstart](../quickstart) for loading pretrained weights, image preprocessing and fine-tuning, and [Feature
Extraction](../feature_extraction) for using the models as backbones.

```py
>>> import timm
>>> model = timm.create_model('hiera_tiny_224.mae_in1k_ft_in1k', pretrained=True)
>>> data_config = timm.data.resolve_model_data_config(model)
```

## Model API support

| Feature | `Hiera` |
|---|---|
| [`features_only=True` feature maps](../model_api#intermediate-features) | ✓ (strides 4, 8, 16, 32) |
| [`forward_intermediates()`](../model_api#intermediate-features) | ✓ |
| [`prune_intermediate_layers()`](../model_api#intermediate-features) | ✓ |
| [Any input size, no changes needed](../model_api#input-size) | ✗ |
| [`set_input_size()`](../model_api#input-size) | ✗ |
| [`dynamic_img_size=True`](../model_api#input-size) | ✗ |
| [`set_grad_checkpointing()`](../model_api#training-hooks) | ✓ |
| [Layer-wise LR decay (`group_matcher()`)](../model_api#training-hooks) | ✓ |
| [`reset_classifier()`](../model_api#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 (`Hiera` with `hiera_tiny_224` at 224), other
architectures of the same class are expected to behave the same. See the [Model API](../model_api) page for details.

## Architectures

| Architecture | Params (M) | GMACs | Input size | Pretrained weights |
|---|---:|---:|---:|---:|
| `hiera_base_224` | 51.52 | 9.40 | 224 | 2 |
| `hiera_base_abswin_256` | 51.27 | 12.46 | 256 | 0 |
| `hiera_base_plus_224` | 69.90 | 12.67 | 224 | 2 |
| `hiera_huge_224` | 672.78 | 124.85 | 224 | 2 |
| `hiera_large_224` | 213.74 | 40.34 | 224 | 2 |
| `hiera_small_224` | 35.01 | 6.42 | 224 | 2 |
| `hiera_small_abswin_256` | 34.36 | 8.29 | 256 | 4 |
| `hiera_tiny_224` | 27.91 | 4.91 | 224 | 2 |

GMACs and parameter counts are for the default input size and classifier of each architecture, from the [benchmark
results](https://github.com/huggingface/pytorch-image-models/tree/main/results).

## Pretrained weights

Top-1 is ImageNet-1k validation accuracy from
[`results-imagenet.csv`](https://github.com/huggingface/pytorch-image-models/blob/main/results/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.

Weights are grouped by source: the paper or origin given in the pretrained config, else a Hub organization other than
`timm`, else the first part of the pretrained tag (`architecture.tag`). Sources with a single weight are listed under
other.

### `mae` tags

| Weight | Input size | Top-1 (%) | Eval size | Classes | License | Hub |
|---|---:|---:|---:|---:|---|---|
| `hiera_base_224.mae` | 224 | - | - | none | cc-by-nc-4.0 | [timm](https://huggingface.co/timm/hiera_base_224.mae) |
| `hiera_base_224.mae_in1k_ft_in1k` | 224 | 84.528 | 224 | 1000 | cc-by-nc-4.0 | [timm](https://huggingface.co/timm/hiera_base_224.mae_in1k_ft_in1k) |
| `hiera_base_plus_224.mae` | 224 | - | - | none | cc-by-nc-4.0 | [timm](https://huggingface.co/timm/hiera_base_plus_224.mae) |
| `hiera_base_plus_224.mae_in1k_ft_in1k` | 224 | 85.136 | 224 | 1000 | cc-by-nc-4.0 | [timm](https://huggingface.co/timm/hiera_base_plus_224.mae_in1k_ft_in1k) |
| `hiera_huge_224.mae` | 224 | - | - | none | cc-by-nc-4.0 | [timm](https://huggingface.co/timm/hiera_huge_224.mae) |
| `hiera_huge_224.mae_in1k_ft_in1k` | 224 | 86.840 | 224 | 1000 | cc-by-nc-4.0 | [timm](https://huggingface.co/timm/hiera_huge_224.mae_in1k_ft_in1k) |
| `hiera_large_224.mae` | 224 | - | - | none | cc-by-nc-4.0 | [timm](https://huggingface.co/timm/hiera_large_224.mae) |
| `hiera_large_224.mae_in1k_ft_in1k` | 224 | 86.046 | 224 | 1000 | cc-by-nc-4.0 | [timm](https://huggingface.co/timm/hiera_large_224.mae_in1k_ft_in1k) |
| `hiera_small_224.mae` | 224 | - | - | none | cc-by-nc-4.0 | [timm](https://huggingface.co/timm/hiera_small_224.mae) |
| `hiera_small_224.mae_in1k_ft_in1k` | 224 | 83.888 | 224 | 1000 | cc-by-nc-4.0 | [timm](https://huggingface.co/timm/hiera_small_224.mae_in1k_ft_in1k) |
| `hiera_tiny_224.mae` | 224 | - | - | none | cc-by-nc-4.0 | [timm](https://huggingface.co/timm/hiera_tiny_224.mae) |
| `hiera_tiny_224.mae_in1k_ft_in1k` | 224 | 82.826 | 224 | 1000 | cc-by-nc-4.0 | [timm](https://huggingface.co/timm/hiera_tiny_224.mae_in1k_ft_in1k) |

### `sbb2` tags

| Weight | Input size | Top-1 (%) | Eval size | Classes | License | Hub |
|---|---:|---:|---:|---:|---|---|
| `hiera_small_abswin_256.sbb2_e200_in12k` | 256 | - | - | 11821 | apache-2.0 | [timm](https://huggingface.co/timm/hiera_small_abswin_256.sbb2_e200_in12k) |
| `hiera_small_abswin_256.sbb2_e200_in12k_ft_in1k` | 256 | 84.912 | 256 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/hiera_small_abswin_256.sbb2_e200_in12k_ft_in1k) |
| `hiera_small_abswin_256.sbb2_pd_e200_in12k` | 256 | - | - | 11821 | apache-2.0 | [timm](https://huggingface.co/timm/hiera_small_abswin_256.sbb2_pd_e200_in12k) |
| `hiera_small_abswin_256.sbb2_pd_e200_in12k_ft_in1k` | 256 | 84.564 | 256 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/hiera_small_abswin_256.sbb2_pd_e200_in12k_ft_in1k) |

