# GPU Image Decoding for AI Pipelines

Canonical page: https://frames-sg.com/gpu-image-decoding-ai/

Frames provides Rust integrations for decoding JPEG 2000 and HTJ2K batches into tensor and resident-device workflows. The codec owns parsing, preparation, compatible-output grouping and execution. The application still owns datasets, labels, sampling, resizing, padding, augmentation, normalization and training policy.

## Burn integration

`j2k-ml` returns rank-four NCHW or NHWC Burn tensors using native `U8`, `U16` or `I16` samples. Owned inputs can request full, region, reduced or region-plus-reduced decoding. Compatible outputs are grouped without padding, with source indices retained for label realignment.

Routes include:

- Persistent CPU batch decode followed by ordinary Burn tensor placement.
- Direct CUDA decoding into Burn-owned device storage without decoded-pixel host readback.
- Staged CUDA or Metal decode, host readback and ordinary framework upload.

Explicit GPU requests fail for unsupported inputs rather than silently switching to the CPU.

## Other integrations

- `j2k-mpsgraph` hands supported resident Apple GPU batches to MPSGraph.
- The optional Rust-written `j2k-python` extension exposes native PyTorch/NumPy tensors, reusable batches, region/reduced decode, selected wavelet bands and a supported direct CUDA-to-PyTorch path.

## Start and references

```sh
cargo add j2k-ml --features cpu
cargo run -p j2k-ml --example training_batcher --features cpu
```

- [Burn API documentation](https://docs.rs/j2k-ml)
- [Burn integration guide](https://github.com/frames-sg/j2k/blob/main/docs/j2k-ml.md)
- [PyTorch/NumPy extension](https://github.com/frames-sg/j2k/tree/main/crates/j2k-python)
- [GPU JPEG 2000 backends](https://frames-sg.com/j2k/gpu-jpeg2000-rust/)
