Skip to main content

Module tiled

Module tiled 

Source
Expand description

Overlap-tiled inference for fully-convolutional deep-learning inversions (onnx).

Whole-volume nets (e.g. xQSM, QSMnet) allocate activations proportional to the entire volume, which overflows a 32-bit WASM heap (4 GB ceiling) on clinical-size data. Because these nets are fully convolutional, they can instead be run patch-by-patch: each output “core” is produced from a patch that includes a halo of surrounding context, then written back — the classic U-Net overlap-tile strategy. Peak memory is bounded by a single patch regardless of volume size.

NOTE: tiling a net trained on whole volumes is an approximation. Dipole inversion is a global operation, so a patch is blind to distant susceptibility sources; a larger halo reduces the resulting low-frequency / boundary error but does not eliminate it.

Structs§

TileConfig
Tiling parameters for tiled_field_inversion.

Functions§

tile_patch_size
Padded input-patch size per axis for a config and the net’s size_divisor: core + 2·halo rounded up to a multiple of divisor. Isotropic, so one value serves all axes. Callers use this to build a reusable OnnxModel::plan_for plan of shape [1, 1, p, p, p].
tiled_field_inversion
Run a fully-convolutional field→χ ONNX net patch-by-patch with a context halo, bounding peak memory to a single patch.
tiled_scatter
Shared overlap-tiling driver. Enumerates the core-aligned tiles that actually touch mask (all-background tiles are skipped → work is restricted to the mask bounding box for free), runs each through run_tile, and scatters the results back into a full-volume buffer (masked). Handles the empty-tile skip, parallel batching, and progress reporting so each model only supplies its own per-patch logic.
tiled_volume_algorithm
Overlap-tile an entire volume→volume algorithm (not just one forward pass). For each tile, a padded sub-volume of field/mask is cut out (with halo context, zero outside the volume), run_patch(field_patch, mask_patch, patch_grid) is run on it, and the central core is written back. Use this for the FFT-unrolled nets (lpcnn/modl-qsm/nextqsm) whose Rust-side physics loop wraps a whole-volume CNN — running the whole algorithm per patch bounds memory. Strongly off-design (the dipole/k-space step then sees only a patch), so results are approximate; callers should warn and steer users to a full-volume run for real work.

Type Aliases§

Tile
A core-aligned tile: (x0, y0, z0, cx, cy, cz) — origin + core extent (clamped at edges).