Skip to main content

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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for canvit-pytorch 0.3.1
File Size Uploaded Provenance Actions
canvit_pytorch-0.3.1.tar.gz 365.1 kB Without provenance Details for canvit_pytorch-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for canvit-pytorch 0.3.1
File Interpreter ABI Platform Actions
canvit_pytorch-0.3.1-py3-none-any.whl Python 3 none any Details for canvit_pytorch-0.3.1-py3-none-any.whl

Total release size: 563.3 kB

Release files / canvit_pytorch-0.3.1.tar.gz

Download URL canvit_pytorch-0.3.1.tar.gz
Size 365.1 kB
Tags Source
SHA-256 checksum
How to use checksums
de30a7935aad28addd349b4b26719b4ae5171269f9b90ef0ee38113bdcbb3fce
BLAKE2b-256 checksum
How to use checksums
4ec39caa16068061e62af4f9787f14de0831aab41dd6d8e35ec7687f08172f37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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.1-py3-none-any.whl

Download URL canvit_pytorch-0.3.1-py3-none-any.whl
Size 198.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a10e74f413283a2ebf44d2b0295b2d2db6ebb277199673e0a827d3b872b580e
BLAKE2b-256 checksum
How to use checksums
91650dbfe03551a233631db39d30a8c3b2485f7d1b99b4f40f80cceb2455a516
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page