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
On Linux, torch's PyPI wheels (2.14 and later) are built for CUDA 13 and cannot use the GPU under an older NVIDIA driver. There, install the torch build for your CUDA version first (PyTorch's selector; in a uv project, uv's PyTorch guide).
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 on the Hub.
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.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| canvit_pytorch-0.3.0.tar.gz | 364.1 kB | Without provenance | Details for canvit_pytorch-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| canvit_pytorch-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for canvit_pytorch-0.3.0-py3-none-any.whl |
Total release size: 561.8 kB
Release files / canvit_pytorch-0.3.0.tar.gz
| Download URL | canvit_pytorch-0.3.0.tar.gz |
|---|---|
| Size | 364.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
40e6be7938678e4471045c904de2563278d936e45d6790ddacfe9b2f895bdbf2
|
|
BLAKE2b-256 checksum How to use checksums |
724face47b24c4e0c902f88be270c00eefeb817edd0ad5d1f178b6ad072b2932
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","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.3.0-py3-none-any.whl
| Download URL | canvit_pytorch-0.3.0-py3-none-any.whl |
|---|---|
| Size | 197.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b9d29d11363f31f236a8808df3a7f1362f5286f3172125fea36bbb9d9239d76d
|
|
BLAKE2b-256 checksum How to use checksums |
336758141e53143b33830f70288ee6b888fdf19a2932c3cb13cf513c31455221
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for canvit-pytorch 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.