learning.Reconstruction#
- class bartorch.learning.Reconstruction#
Bases:
LightningModuleLightning module training one of the three stages of an unrolled reconstruction network.
"denoiser"trains the network alone, on pairs of a degraded image and its reference."greedy"trains anUnrolledbuilt withdetach=True, back-propagating a loss on each iteration’s image before the next iteration runs; the losses grow geometrically, the lastratiotimes the first."end-to-end"takes the loss on the last image through the whole stack, whichcheckpoint=Truemakes affordable.
Run in this order, each from the weights the previous one left, these are the staged training of Urman et al.
Items are dictionaries and a batch is a list of them (
collate_fn=list), since operators and k-space vary between subjects:"denoiser":inputandtargetimages, and optionallystep,sigmaandlabelpassed to the network;the unrolled stages: the data
yand its encodingA; the reference imagetarget, or the samplingpatternfor self-supervised training; optionallyx0.
Any item may carry
weights, multiplying the voxel-wise error of the default loss. Batches are not moved to the trainer’s device: aPatchwisenetwork or an operator with operands on the host moves what it needs.An item without
targetis trained self-supervised (SSDU): itspatternis partitioned bysplit()at every step, the network reconstructs from one part, and the loss is the normalized \(\ell_1 + \ell_2\) error of the held-out k-space. The validation partition is the same at every epoch.Optimization is manual: gradients are accumulated over
accumulateitems, optionally clipped, and applied with Adam; the learning rate is multiplied byfactorafterpatienceepochs without improvement of the loggedval_loss.- Parameters:
model (nn.Module) – The network for
"denoiser", anUnrolledfor the other stages.stage ({"denoiser", "greedy", "end-to-end"}, default="end-to-end") – Training stage.
loss (callable, default=None) –
loss(prediction, target, item)for supervised items; the mean modulus of the error when omitted.ratio (float, default=10.0) – Weight of the last iteration’s loss relative to the first’s, in the greedy stage.
lr (float, default=1e-3) – Adam’s learning rate.
weight_decay (float, default=0.0) – Adam’s weight decay.
factor (float, default=0.5) – Multiplier of the learning rate on a plateau of
val_loss.patience (int, default=10) – Epochs without improvement of
val_lossbefore the learning rate is reduced.accumulate (int, default=1) – Items whose gradients are summed before an optimizer step.
clip (float, default=None) – Maximum norm of the gradient; no clipping when omitted.
fraction (float, default=0.4) – Share of the acquired samples held out, for self-supervised items.
split_options (dict, default=None) – Further keywords of
split().
- Raises:
ValueError – An unknown
stage;"greedy"with a model not built withdetach=True;accumulatebelow one. In training,"greedy"with a block whose image does not depend on that iteration’s parameters, such asADMMBlock, whose image is the conjugate-gradient update preceding the denoiser;ISTBlockqualifies.
References
Urman Y, Nishimura M, Abraham D, Cao X, Setsompop K. Fully 3D unrolled magnetic resonance fingerprinting reconstruction via staged pretraining and implicit gridding. Magn Reson Med 96(5):2516-2529, 2026. https://doi.org/10.1002/mrm.70500
Examples
>>> stage = learning.Reconstruction(model, stage="greedy", accumulate=4) >>> trainer = lightning.Trainer(max_epochs=50, callbacks=[EarlyStopping("val_loss")]) >>> trainer.fit(stage, DataLoader(train, collate_fn=list), DataLoader(valid, collate_fn=list))
- transfer_batch_to_device()#
Leave the batch where the dataset put it.
- configure_optimizers()#
Adam over the trainable parameters, reduced on a plateau of
val_loss.
- training_step()#
Back-propagate each item of a list and step every
accumulateitems.
- validation_step()#
Log the mean loss of the items as
val_loss.
- on_validation_epoch_end()#
Step the plateau scheduler on
val_loss.