nmjfry/active-vision-transformers
关于
Active Vision Transformers 👁️ foveated ViTs with persistent memory. Up to 10x fewer FLOPs, runs DINOv3-B at up to 90fps on iPhone 13. Pretrained models & code for training your own active ViTs.
人工智能与机器学习实测星标增长
- 24小时
- 正在收集历史
- 7天
- 正在收集历史
- 15天
- 正在收集历史
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Active Vision Transformers
Nicholas Fry*
·
Shinjeong Kim*
·
Maciej Lewandowski
·
Marwan Taher
Piotr Dudek
·
Paul H. J. Kelly
·
Andrew J. Davison
(* Equal contribution)
Paper | Video | Project Page | Models

Overview
This code is for turning a pretrained ViT into an active one. An active vision transformer (aViT) accumulates information about a frame or video through a sequence of glimpses.
The method has three parts:
- Foveation. Each glimpse is detailed at the point of fixation and coarse in the periphery, so it has far fewer tokens than the whole frame.
- Fine-tuning. A pretrained ViT, the teacher, is run on the whole frame. A copy of the teacher, the student, is fine-tuned to work on foveated glimpses. Nothing is trained from scratch.
- Memory. The student writes each glimpse to a memory (the canvas), which is supervised with the teacher's output for the whole frame. The memory is updated after each glimpse and is kept from one video frame to the next. Downstream tasks read the memory in place of the teacher's output.
You choose where the model looks. The fixations can come from a fixed schedule, an object detector or a person's gaze. We train with random fixations, so the model works with any of these.
This repository contains the avit package, the training script and the benchmark we use to score trained models
(benchmark/).
Install
git clone https://github.com/nmjfry/active-vision-transformers
cd active-vision-transformers
uv sync
source .venv/bin/activate
This uses uv to create .venv with Python 3.11 and the package versions in uv.lock. These
are the versions we tested with (torch 2.9 with CUDA 12.8). Run the commands below from the repository folder with the
environment active.
If you do not use uv, run pip install -e . in your own environment. This installs the latest versions of the packages
listed in pyproject.toml. The benchmark has a separate environment (see benchmark/README.md).
To train your own model, you also need the pretrained weights of the ViT you start from. For the default, DINOv3 ViT-B/16,
accept Meta's DINOv3 License on Hugging Face and download facebook/dinov3-vitb16-pretrain-lvd1689m. The licence of the
pretrained weights also applies to models trained from them.
Running a model
Pretrained checkpoints (DINOv3, DINOv2, C-RADIOv3, iBOT and VGGT-Ω) are on Hugging Face at Small-ML/aViT. Each file contains its own standardisation statistics:
from huggingface_hub import hf_hub_download
import avit
ckpt = hf_hub_download("Small-ML/aViT", "avit_dinov3_vitb16_512.pt")
model = avit.load(ckpt)
scene = avit.scene_from_image("photo.jpg", model.frame) # (3, 512, 512) uint8
out = model.run(scene, fixations=[(256, 256), (100, 400)]) # two glimpses, (x, y) in pixels
out["features"] # (1, 2, 32, 32, 768): the predicted feature map after each glimpse
nxt = model.run(next_frame, fixations=[(300, 200)], canvas=out["last"]) # keep the memory for the next frame
For a local training checkpoint (before export.py), pass its statistics file as well:
avit.load("runs/avit512_s0/best.pt", stats="runs/stats_dinov3_vitb16_crop512.pt"). A scene is a square image, and
scene_from_image takes the centre square of any image. You can pass scenes and fixations in batches.
Use zoom to change the scale of a glimpse. zoom=2 halves the size of every token, which gives a finer glimpse over a
smaller area. zoom=0.5 does the opposite.
The default glimpse uses the foveation pattern from Segment This Thing, but the model is not tied to it. You can put several fixations in one glimpse, or pass your own set of square boxes:
import numpy as np
fx = np.random.randint(0, 512, (1, 4, 3, 2)) # 1 scene, 4 glimpses, 3 fixations in each
out = model.run(scene, fx, case="tile64") # the fixations share one tiling of the scene
boxes = np.array([(x, y, 128) for y in range(0, 512, 128) for x in range(0, 512, 128)] # (x0, y0, side) in pixels,
+ [(224 + 16 * i, 224 + 16 * j, 16) for j in range(4) for i in range(4)]) # side a multiple of 16
out = model.run(scene, fixations=[(256, 256)], boxes=[[boxes]])
A model trained on single fixations already works with these glimpses. Fine-tuning on them gives better results (see
Training). The docstring in avit/inference.py describes all the arguments.
Data
We train on video frames from SA-V. Download the tars of the SA-V training split and run:
python prepare_sav.py --raw RAW --tars sav_000,sav_001 --out SAV
This extracts the frames into the folder layout that the training script reads. We used the first eight tars for the paper.
To train on other data, put it in the same layout, which is described in avit/data.py.
Training

python train_canvas.py --name avit512_s0 --data $SAV --weights $DV3 --stats runs/stats_dinov3_vitb16_crop512.pt
Here $SAV is the prepared data folder and $DV3 is the folder with the DINOv3 ViT-B/16 weights.
By default this trains the model described in the paper: 100,000 steps at batch size 32 on 512 px frames. For a shorter run,
add --steps 20000 --batch 8. This takes about 80 minutes and 13 GB of GPU memory on one RTX 5090. The statistics file
stores the mean and standard deviation of the teacher's features. It is created on the first run if it does not exist.
Checkpoints and validation metrics are saved to runs/<name>/. To resume a run, run the same command again. To train as a
Slurm job, use slurm/train.sbatch.
The main options:
| Option | Default | |
|---|---|---|
--name |
required | name of the run |
--data |
required | prepared data folder |
--weights |
required | folder with the pretrained weights |
--stats |
required | statistics file (created if it does not exist) |
--backbone |
dinov3_vitb16 |
which pretrained ViT to start from (see Other backbones) |
--frame |
crop512 |
crop512 trains on 512 px frames with a 32 x 32 memory, 720 on 720 px frames with a 45 x 45 memory |
--steps |
100000 | number of training steps |
--batch |
32 | batch size |
--seed |
0 | random seed |
--out-root |
runs |
folder where runs are saved |
--finetune-from |
checkpoint of a finished run to start from |
Run python train_canvas.py -h to see every option with its default. The other options are the ones we varied in the
paper's ablations: the training sequences, the optimiser, the position encodings and the memory update.
Two extensions use the same script:
- To fine-tune a trained model on glimpses with several fixations, add
--finetune-from RUN/last.pt --tile --batch 16 --steps 15000. - To also predict the teacher's CLS token, for classification, add
--cls-out glimpse --cls-acc --cls-grad. This works with the DINOv3 backbones.model.runthen also returnsout["cls"].
Other backbones
Use --backbone to start from a different pretrained ViT. The same model is used as the teacher and as the starting point
of the student.
--backbone |
Model |
|---|---|
dinov3_vitb16 (default), dinov3_vits16, dinov3_vitl16, dinov3_vith16plus |
DINOv3 |
dinov2_vitb14_reg |
DINOv2 ViT-B/14 with registers |
pe_spatial_b16 |
Perception Encoder, PE-Spatial-B16-512 |
cradio_v3_b |
C-RADIOv3-B |
ibot_vitb16, ibot_vitb16_in22k |
iBOT ViT-B/16 |
siglip2_b16 |
SigLIP 2 B/16 |
vggt_omega_enc |
the DINOv3 ViT-L/16 encoder inside VGGT-Ω |
python train_canvas.py --backbone pe_spatial_b16 --name avit512_pe_s0 --data $SAV --weights $PE \
--stats runs/stats_pe_spatial_b16_crop512.pt
The code loads each model's released weight file directly, so you do not need to install the original packages.
avit/backbones.py lists the file that each weights folder needs to contain. Do not compare backbones by their feature
loss, because each teacher has its own feature scale. Compare them with a task score.
Adding a backbone. Add an entry to REGISTRY in avit/backbones.py with the model's size, pixel normalisation,
position encoding and patch size. If the weights use different parameter names, also write a function that maps them (see
from_pe and from_dinov2 in avit/vit.py). Then check that the teacher gives the same features as the official
implementation on the same images.
Using a different target. The code assumes that the student and the teacher are the same model, so the target has the
same width as the student's tokens. The method does not require this. You could supervise the memory with another model's
features, or with a task output such as depth. For this you would need a Teacher (avit/teacher.py) that returns one
vector per patch, and a read-out of the matching size (head and dmap in avit/canvas.py). We have not tried this.
Using aViT inside a larger model. A model that was trained on the original ViT's features may need adapting to work with aViT's features. In the paper we do this for VGGT-Ω. We freeze the trained aViT, add LoRA to the linear layers of VGGT-Ω and train only the LoRA to reproduce the outputs of the original pipeline. This step depends on the VGGT-Ω code and is not included here.
Evaluating and exporting
python evaluate.py --ckpt runs/avit512_s0/best.pt --stats runs/stats_dinov3_vitb16_crop512.pt --data $SAV --weights $DV3
python export.py --ckpt runs/avit512_s0/best.pt --stats runs/stats_dinov3_vitb16_crop512.pt --out avit512.pt
evaluate.py prints the feature loss on held-out frames and clips. export.py saves the model and its statistics in a
single file, which avit.load reads without the stats argument.
The feature loss does not tell you how well the features work on a task. For that, use the benchmark in benchmark/. It
scores a model on video object segmentation, semantic segmentation, depth, correspondence and classification. Run
make_bench_folder.py to prepare a trained model for it, and see benchmark/README.md for the rest.
Files
avit/fovea.py, tokensets.py |
make the tokens of a glimpse (default pattern, several fixations, your own boxes) |
avit/encoder.py |
the student ViT, which runs on foveated tokens |
avit/canvas.py |
the memory and how a glimpse updates it |
avit/teacher.py, backbones.py, dinov3.py, vit.py, vggt_omega.py |
the teacher and the supported pretrained ViTs |
avit/inference.py |
avit.load and model.run |
avit/data.py, validate.py |
data loading and validation |
train_canvas.py, fit_stats.py, prepare_sav.py, slurm/ |
training |
evaluate.py, export.py, make_bench_folder.py, benchmark/ |
evaluation |
Acknowledgements
We thank the developers and contributors of the open-source projects that our code builds on.
Citation
@article{fry2026active,
title={Active Vision Transformers},
author={Fry, Nicholas and Kim, Shinjeong and Lewandowski, Maciej and Taher, Marwan and Dudek, Piotr and Kelly, Paul H. J. and Davison, Andrew J.},
journal={arXiv preprint arXiv:2611.39952},
year={2026}
}
Licence
The code in this repository is released under the MIT licence (see LICENCE), except for the third-party code, assets and
data listed in NOTICE.md, which keep their own licences. Pretrained weights are subject to the licences of their starting
backbones (see NOTICE.md).
探索相关项目
加载中…