AI ingestion / Rust / CUDA + Metal

GPU Image Decoding for AI

Decode JPEG 2000 and HTJ2K batches into integer tensors or resident device buffers. Keep codec work separate from dataset policy, augmentation and model preprocessing.

The codec owns pixels. Your application owns training.

Frames prepares and groups encoded images, executes supported codec routes, and returns the decoded rectangles and source indices. Sampling, labels and model policy remain with the application.

Batch preparation

Group compatible outputs without padding

Owned inputs can request full, region, reduced or region-plus-reduced decoding. The codec groups compatible dimensions, layouts and native sample types while retaining source order metadata.

Tensor outputs

Native integer NCHW or NHWC

j2k-ml returns rank-four Burn tensors as U8, U16 or I16. Float conversion and normalization remain ordinary tensor operations.

Device routes

Direct or staged handoff

CUDA can decode into Burn-owned device storage. Staged CUDA and Metal routes read completed output through host memory before ordinary framework upload. The route is explicit.

Choose the boundary your stack needs.

Rust / Burn

j2k-ml batch adapter

CPU, direct CUDA, staged CUDA and staged Metal routes create ordinary Burn tensors while preserving codec group and failure information.

Apple

j2k-mpsgraph resident batches

Supported decoded batches can be handed to Apple MPSGraph without leaving the GPU. This integration adds no codec formats beyond J2K’s support boundary.

Python boundary

j2k-python PyTorch and NumPy

The optional Rust-written extension exposes native pixel tensors, reusable batches, region and reduced decode, selected wavelet bands, and a supported direct CUDA-to-PyTorch route.

Run a complete batch example.

The examples make the dataset, batching and device-transfer ownership visible. Explicit accelerator routes return errors for unsupported inputs rather than falling back silently.

Portable BurnCPU codec
$ cargo add j2k-ml --features cpu
$ cargo run -p j2k-ml --example training_batcher --features cpu

Dataset → DataLoader → Batcher with source-index realignment and tensor normalization.

Direct CUDABurn-owned destination
$ cargo run -p j2k-ml --example cuda_direct --features cuda

Decode into the final Burn CUDA allocation without decoded-pixel host readback.

Feed the pipeline