canvit-mlx
The MLX implementation of CanViT (Canvas Vision Transformer) for Apple Silicon. Read the root backend documentation for the cross-backend API and tensor conventions.
Install
uv add canvit-mlx
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 mlx.core as mx
from PIL import Image
from canvit_mlx import CanViTForSemanticSegmentation, Viewpoint, sample_at_viewpoint
from canvit_mlx.preprocess import preprocess
scene = mx.array(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-mlx",
probe_repo="canvit/probe-ade20k-40k-s512-c64-in21k-mlx",
)
model.eval()
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)
mx.eval(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 MLX collection also contains native fine-tuned classifiers and other published exports.
Develop from a checkout
cd canvit-mlx
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-mlx python -m tools.convert_checkpoints --help
Metadata
Release files for canvit-mlx 0.2.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 | |
|---|---|---|---|
| canvit_mlx-0.2.0.tar.gz | 63.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| canvit_mlx-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 80.4 kB
Release files / canvit_mlx-0.2.0.tar.gz
| Download URL | canvit_mlx-0.2.0.tar.gz |
|---|---|
| Size | 63.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5284f9a4f9abcb466906e4e865c285c5ba6a133a153b14aba9b163864470deac
|
|
BLAKE2b-256 checksum How to use checksums |
9fe8fbd35bde3ec4be084f2b7a0094a4a967803315e05a4b0bb036ee5f0dcfde
|
| 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_mlx-0.2.0-py3-none-any.whl
| Download URL | canvit_mlx-0.2.0-py3-none-any.whl |
|---|---|
| Size | 17.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
420e433062da57404c2014817ca7904e100acb110b00ee1c5073d70e2b2737d8
|
|
BLAKE2b-256 checksum How to use checksums |
e3ce9768b688728c8907ee8c67e0ab645ce65b52730576a65cf7cdda6c90f13b
|
| 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}
|