Skip to main content

canvit-nnx

The JAX and Flax NNX implementation of CanViT (Canvas Vision Transformer). Read the root backend documentation for the cross-backend API and tensor conventions.

Install

uv add canvit-nnx

Load a Hugging Face checkpoint

Load a pretrained model and an ADE20K probe from Hugging Face. Replace path/to/image.jpg with your image path.

import jax
import jax.numpy as jnp
from PIL import Image

from canvit_nnx import CanViTForSemanticSegmentation, Viewpoint, sample_at_viewpoint
from canvit_nnx.preprocess import preprocess

scene = jnp.asarray(preprocess(512)(Image.open("path/to/image.jpg").convert("RGB")))[None]
model = CanViTForSemanticSegmentation.from_pretrained_with_probe(
    pretrained_repo="canvit/canvitb16-add-vpe-pretrain-g128px-s512px-in21k-dv3b16-2026-02-02-nnx",
    probe_repo="canvit/probe-ade20k-40k-s512-c64-in21k-nnx",
)
model.eval()  # Flax NNX mutates the module and returns None.
viewpoint = Viewpoint.full_scene(batch_size=1)
state = model.init_state(batch_size=1, canvas_grid_size=64)
glimpse = sample_at_viewpoint(spatial=scene, viewpoint=viewpoint, glimpse_size_px=128)
logits, state = model(glimpse=glimpse, state=state, viewpoint=viewpoint)
jax.block_until_ready(logits)
print(logits.shape)  # [1, 64, 64, 150]

The model and probe remain separate checkpoints. They use NHWC arrays: scenes and glimpses are [B, H, W, 3], and the wrapper returns canvas logits as [B, G, G, num_classes]. Viewpoint centers use (row, col) scene coordinates in [-1, 1]; each scale is the crop's half-side.

The example uses the ImageNet-21k CanViT-B checkpoint and the ADE20K probe. The Hub lists every NNX checkpoint by its nnx tag.

Constructing a model without a checkpoint requires an explicit parameter RNG, for example:

from flax import nnx
from canvit_nnx import CanViT, CanViTConfig

model = CanViT(CanViTConfig(), rngs=nnx.Rngs(0))

Fine-tune on ImageNet-1k

canvit_nnx.specialize.in1k fine-tunes CanViT-B for ImageNet-1k classification with the paper's recipe, in bfloat16 with fused Pallas kernels on TPU. It is new in canvit-nnx 0.3.0 and needs the train extra; its README describes the data and the command.

Detect objects on COCO

canvit_nnx.detect trains CanViT-B with a CenterNet head for COCO 2017 object detection and scores average precision after each glimpse, on one host or a multi-host TPU slice. It is new in canvit-nnx 0.3.0 and needs the train extra; its README describes the data and the commands.

Develop from a checkout

cd canvit-nnx
uv sync

The checkout resolves canvit-core from its sibling directory. To convert a PyTorch checkpoint and run the conversion checks from the repository root:

uv run --project canvit-nnx python -m tools.convert_checkpoints --help

Metadata

Release files for canvit-nnx 0.3.0

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-nnx 0.3.0
File Size Uploaded Provenance Actions
canvit_nnx-0.3.0.tar.gz 161.7 kB Without provenance Details for canvit_nnx-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for canvit-nnx 0.3.0
File Interpreter ABI Platform Actions
canvit_nnx-0.3.0-py3-none-any.whl Python 3 none any Details for canvit_nnx-0.3.0-py3-none-any.whl

Total release size: 234.3 kB

Release files / canvit_nnx-0.3.0.tar.gz

Download URL canvit_nnx-0.3.0.tar.gz
Size 161.7 kB
Tags Source
SHA-256 checksum
How to use checksums
78d6d54469a9ceb2cbcc010718869d5c89f01a81e10a6dab716251051a6ce8b7
BLAKE2b-256 checksum
How to use checksums
ef07f7d2d8dfb43c07846de199971807c3f83d8d99ca3084625016f2fa56bdec
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_nnx-0.3.0-py3-none-any.whl

Download URL canvit_nnx-0.3.0-py3-none-any.whl
Size 72.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2e2a6493749ac0102a26a7a4443b62f705f391b89b55c8f98bfb57cdad0073e1
BLAKE2b-256 checksum
How to use checksums
86897d26a289da12b1a866b92a83e1b6ef5cf99ecbec828807117582289b4674
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-nnx 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.

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