canvit-pytorch
The PyTorch implementation of CanViT (Canvas Vision Transformer). It contains the model, checkpoint loading, preprocessing, policies, pretraining, task specialization, and evaluation code. The paper is CanViT: Toward Active-Vision Foundation Models (NeurIPS 2026).
Install
uv add canvit-pytorch
Load a Hugging Face checkpoint
This example loads a PyTorch checkpoint, processes a user-provided image, and returns the recurrent state after one glimpse. Replace the image path with an RGB image available to your environment.
import torch
from PIL import Image
from canvit_pytorch import CanViTForPretraining, Viewpoint, sample_at_viewpoint
from canvit_pytorch.preprocess import preprocess
scene = preprocess(512)(Image.open("path/to/image.jpg").convert("RGB")).unsqueeze(0)
model = CanViTForPretraining.from_pretrained(
"canvit/canvitb16-add-vpe-pretrain-g128px-s512px-in21k-dv3b16-2026-02-02"
).eval()
viewpoint = Viewpoint.full_scene(batch_size=1, device=scene.device)
state = model.init_state(batch_size=1, canvas_grid_size=32)
glimpse = sample_at_viewpoint(spatial=scene, viewpoint=viewpoint, glimpse_size_px=128)
with torch.inference_mode():
output = model(glimpse=glimpse, state=state, viewpoint=viewpoint)
print(output.state.recurrent_cls.shape) # [1, 1, 768]
The example uses the ImageNet-21k pretrained CanViT-B checkpoint.
The fine-tuned ImageNet-1k classifier
and separate task probes are also available from the PyTorch checkpoints.
The root README documents classification,
segmentation, native backends, and the training and evaluation entry points.
PyTorch inputs use NCHW: scenes and feature maps are
[B, C, H, W], while model glimpses are [B, 3, h, w]. Viewpoint centers use
(row, col) scene coordinates in [-1, 1]; each scale is the crop's
half-side.
MIT license. See LICENSE.
Metadata
Release files for canvit-pytorch 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| canvit_pytorch-0.2.1.tar.gz | 342.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| canvit_pytorch-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 521.7 kB
Release files / canvit_pytorch-0.2.1.tar.gz
| Download URL | canvit_pytorch-0.2.1.tar.gz |
|---|---|
| Size | 342.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d6404d54414aead0102ec3a3dd8c12651f1c2344660d652e7dba0d02cfea66f0
|
|
BLAKE2b-256 checksum How to use checksums |
5d521c4ea41744f1f98f1a7148bf6b478ded5b43b7f643daa3e230c29c01a585
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / canvit_pytorch-0.2.1-py3-none-any.whl
| Download URL | canvit_pytorch-0.2.1-py3-none-any.whl |
|---|---|
| Size | 179.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be96d2464096e34da06c63047e6b409f6faa3d2fbc214fa94ea7a21a3601790c
|
|
BLAKE2b-256 checksum How to use checksums |
19350b10c8d19f65a734cbf56a7212ec9efbf9c94966a82b1614d3e2e0b1ff2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|