Skip to main content

Module qsmnet

Module qsmnet 

Source
Expand description

QSMnet deep-learning dipole inversion (onnx feature).

QSMnet is a 3D U-Net (SNU-LIST) that maps a local field (ppm) to susceptibility (ppm). The upstream weights are TensorFlow, but we ship a clean PyTorch re-export (scripts/onnx-export/export_qsmnet.py): the plain U-Net rebuilt in PyTorch with the TF weights ported in, giving a tidy NCDHW ONNX ([1, 1, X, Y, Z]) that the pure-Rust tract engine runs — unlike the tf2onnx graph, whose NHWC↔NCHW Reshape/Transpose ops tract can’t analyse. This mirrors the authors’ inference (Code/inference.py): normalize by the dataset mean/std shipped with the checkpoint, centered zero-pad each dim to a multiple of 16 (four pool/deconv levels), run, crop, de-normalize, and mask.

Weights are not bundled; the caller passes the exported qsmnet.onnx bytes (see crate::models).

Structs§

QsmnetNorm
Dataset normalization constants stored beside a QSMnet checkpoint (norm_factor_<name>.mat): field_n = (field - in_mean)/in_std, and chi = out_std*pred + out_mean.

Functions§

qsmnet
Run QSMnet dipole inversion.
qsmnet_tiled
Memory-bounded QSMnet via overlap-tiling — the fully-convolutional U-Net run patch-by-patch (for 32-bit WASM, where whole-volume qsmnet overflows the heap on clinical data). The dataset normalization is applied per value inside the tile loop and the net’s pool depth requires a /16 patch. Approximates whole-volume up to tile-boundary error; see crate::inversion::tiled.