mridc.collections.quantitative.models package

Subpackages

Submodules

mridc.collections.quantitative.models.base module

class mridc.collections.quantitative.models.base.BaseqMRIReconstructionModel(cfg: DictConfig, trainer: Optional[Trainer] = None)[source]

Bases: BaseMRIReconstructionModel, ABC

Base class of all quantitative MRIReconstruction models.

static process_inputs(R2star_map_init, S0_map_init, B0_map_init, phi_map_init, y, mask)[source]

Processes the inputs to the method.

Parameters
  • R2star_map_init (R2* map.) – list of torch.Tensor, shape [batch_size, n_x, n_y]

  • S0_map_init (S0 map.) – list of torch.Tensor, shape [batch_size, n_x, n_y]

  • B0_map_init (B0 map.) – list of torch.Tensor, shape [batch_size, n_x, n_y]

  • phi_map_init (Phi map.) – list of torch.Tensor, shape [batch_size, n_x, n_y]

  • y (Subsampled k-space data.) – list of torch.Tensor, shape [batch_size, n_echoes, n_coils, n_x, n_y, 2]

  • mask (Sampling mask.) – list of torch.Tensor, shape [batch_size, 1, n_x, n_y, 1]

Returns

  • R2star_map_init (Initial R2 map.*) – torch.Tensor, shape [batch_size, n_x, n_y]

  • S0_map_init (Initial S0 map.) – torch.Tensor, shape [batch_size, n_x, n_y]

  • B0_map_init (Initial B0 map.) – torch.Tensor, shape [batch_size, n_x, n_y]

  • phi_map_init (Initial phi map.) – torch.Tensor, shape [batch_size, n_x, n_y]

  • y (Subsampled k-space data.) – torch.Tensor, shape [batch_size, n_echoes, n_coils, n_x, n_y, 2]

  • mask_brain (Brain mask to regularize the inputs.) – torch.Tensor, shape [batch_size, 1, n_x, n_y, 1]

  • mask (Sampling mask.) – torch.Tensor, shape [batch_size, 1, n_x, n_y, 1]

  • r (Random index.) – int

process_quantitative_loss(target, pred, mask_brain, map, _loss_fn)[source]

Processes the loss.

Parameters
  • target (Target data.) – torch.Tensor, shape [batch_size, n_x, n_y, 2]

  • pred (Final prediction(s).) – list of torch.Tensor, shape [batch_size, n_x, n_y, 2], or torch.Tensor, shape [batch_size, n_x, n_y, 2]

  • mask_brain (Mask for brain.) – torch.Tensor, shape [batch_size, n_x, n_y, 1]

  • map (Type of map to regularize the loss.) – str in {“R2star”, “S0”, “B0”, “phi”}

  • _loss_fn (Loss function.) – torch.nn.Module, default torch.nn.L1Loss()

Returns

loss – If self.accumulate_loss is True, returns an accumulative result of all intermediate losses.

Return type

torch.FloatTensor, shape [1]

process_reconstruction_loss(target, pred, _loss_fn)[source]

Processes the loss.

Parameters
  • target (Target data.) – torch.Tensor, shape [batch_size, n_x, n_y, 2]

  • pred (Final prediction(s).) – list of torch.Tensor, shape [batch_size, n_x, n_y, 2], or torch.Tensor, shape [batch_size, n_x, n_y, 2]

  • _loss_fn (Loss function.) – torch.nn.Module, default torch.nn.L1Loss()

Returns

loss – If self.accumulate_loss is True, returns an accumulative result of all intermediate losses.

Return type

torch.FloatTensor, shape [1]

test_epoch_end(outputs)[source]

Called at the end of test epoch to aggregate outputs.

Parameters

outputs (List of outputs of the test batches.) – list of dicts

Return type

Saves the reconstructed images to .h5 files.

test_step(batch: Dict[float, Tensor], batch_idx: int) Tuple[str, int, Tensor][source]

Performs a test step.

Parameters
  • batch (Batch of data. List for multiple acceleration factors. Dict[str, torch.Tensor], with keys,) –

    ‘R2star_map_init’: R2* initial map.

    list of torch.Tensor, shape [batch_size, n_x, n_y]

    ’R2star_map_target’: R2* target map.

    torch.Tensor, shape [batch_size, n_x, n_y]

    ’S0_map_init’: S0 initial map.

    list of torch.Tensor, shape [batch_size, n_x, n_y]

    ’S0_map_target’: S0 target map.

    torch.Tensor, shape [batch_size, n_x, n_y]

    ’B0_map_init’: B0 initial map.

    list of torch.Tensor, shape [batch_size, n_x, n_y]

    ’B0_map_target’: B0 target map.

    torch.Tensor, shape [batch_size, n_x, n_y]

    ’phi_map_init’: Phi initial map.

    list of torch.Tensor, shape [batch_size, n_x, n_y]

    ’phi_map_target’: Phi target map.

    torch.Tensor, shape [batch_size, n_x, n_y]

    ’TEs’: Echo times.

    list of float

    ’kspace’: k-space data.

    torch.Tensor, shape [batch_size, n_echoes, n_coils, n_x, n_y, 2]

    ’y’: Subsampled k-space data.

    list of torch.Tensor, shape [batch_size, n_echoes, n_coils, n_x, n_y, 2]

    ’sensitivity_maps’: Coils sensitivity maps.

    torch.Tensor, shape [batch_size, n_coils, n_x, n_y, 2]

    ’mask’: Sampling mask.

    list of torch.Tensor, shape [1, 1, n_x, n_y, 1]

    ’mask_brain’: Brain mask.

    torch.Tensor, shape [n_x, n_y]

    ’init_pred’: Initial prediction.

    torch.Tensor, shape [batch_size, 1, n_x, n_y, 2] or None

    ’target’: Target data.

    torch.Tensor, shape [batch_size, n_x, n_y] or None

    ’fname’: File name.

    str

    ’slice_num’: Slice number.

    int

    ’acc’: Acceleration factor of the sampling mask.

    float

  • batch_idx (Batch index.) – int

Returns

  • name (Name of the volume.) – str

  • slice_num (Slice number.) – int

  • pred (Predicted data.) – torch.Tensor, shape [batch_size, n_x, n_y, 2]

train_epoch_end(outputs)[source]

Called at the end of train epoch to aggregate the loss values.

Parameters

outputs (List of outputs from the train step.) – list of dicts

training: bool
training_step(batch: Dict[float, Tensor], batch_idx: int) Dict[str, Tensor][source]

Performs a training step.

Parameters
  • batch (Batch of data. List for multiple acceleration factors. Dict[str, torch.Tensor], with keys,) –

    ‘R2star_map_init’: R2* initial map.

    list of torch.Tensor, shape [batch_size, n_x, n_y]

    ’R2star_map_target’: R2* target map.

    torch.Tensor, shape [batch_size, n_x, n_y]

    ’S0_map_init’: S0 initial map.

    list of torch.Tensor, shape [batch_size, n_x, n_y]

    ’S0_map_target’: S0 target map.

    torch.Tensor, shape [batch_size, n_x, n_y]

    ’B0_map_init’: B0 initial map.

    list of torch.Tensor, shape [batch_size, n_x, n_y]

    ’B0_map_target’: B0 target map.

    torch.Tensor, shape [batch_size, n_x, n_y]

    ’phi_map_init’: Phi initial map.

    list of torch.Tensor, shape [batch_size, n_x, n_y]

    ’phi_map_target’: Phi target map.

    torch.Tensor, shape [batch_size, n_x, n_y]

    ’TEs’: Echo times.

    list of float

    ’kspace’: k-space data.

    torch.Tensor, shape [batch_size, n_echoes, n_coils, n_x, n_y, 2]

    ’y’: Subsampled k-space data.

    list of torch.Tensor, shape [batch_size, n_echoes, n_coils, n_x, n_y, 2]

    ’sensitivity_maps’: Coils sensitivity maps.

    torch.Tensor, shape [batch_size, n_coils, n_x, n_y, 2]

    ’mask’: Brain & sampling mask.

    list of torch.Tensor, shape [1, 1, n_x, n_y, 1]

    ’mask_brain’: Brain mask.

    torch.Tensor, shape [n_x, n_y]

    ’init_pred’: Initial prediction.

    torch.Tensor, shape [batch_size, 1, n_x, n_y, 2] or None

    ’target’: Target data.

    torch.Tensor, shape [batch_size, n_x, n_y] or None

    ’fname’: File name.

    str

    ’slice_num’: Slice number.

    int

    ’acc’: Acceleration factor of the sampling mask.

    float

  • batch_idx (Batch index.) – int

Returns

  • Dict[str, torch.Tensor], with keys,

  • ’loss’ (loss,) – torch.Tensor, shape [1]

  • ’log’ (log,) – dict, shape [1]

validation_epoch_end(outputs)[source]

Called at the end of validation epoch to aggregate outputs.

Parameters

outputs (List of outputs of the validation batches.) – list of dicts

Returns

metrics – dict

Return type

Dictionary of metrics.

validation_step(batch: Dict[float, Tensor], batch_idx: int) Dict[source]

Performs a validation step.

Parameters
  • batch (Batch of data. List for multiple acceleration factors. Dict[str, torch.Tensor], with keys,) –

    ‘R2star_map_init’: R2* initial map.

    list of torch.Tensor, shape [batch_size, n_x, n_y]

    ’R2star_map_target’: R2* target map.

    torch.Tensor, shape [batch_size, n_x, n_y]

    ’S0_map_init’: S0 initial map.

    list of torch.Tensor, shape [batch_size, n_x, n_y]

    ’S0_map_target’: S0 target map.

    torch.Tensor, shape [batch_size, n_x, n_y]

    ’B0_map_init’: B0 initial map.

    list of torch.Tensor, shape [batch_size, n_x, n_y]

    ’B0_map_target’: B0 target map.

    torch.Tensor, shape [batch_size, n_x, n_y]

    ’phi_map_init’: Phi initial map.

    list of torch.Tensor, shape [batch_size, n_x, n_y]

    ’phi_map_target’: Phi target map.

    torch.Tensor, shape [batch_size, n_x, n_y]

    ’TEs’: Echo times.

    list of float

    ’kspace’: k-space data.

    torch.Tensor, shape [batch_size, n_echoes, n_coils, n_x, n_y, 2]

    ’y’: Subsampled k-space data.

    list of torch.Tensor, shape [batch_size, n_echoes, n_coils, n_x, n_y, 2]

    ’sensitivity_maps’: Coils sensitivity maps.

    torch.Tensor, shape [batch_size, n_coils, n_x, n_y, 2]

    ’mask’: Brain & sampling mask.

    list of torch.Tensor, shape [1, 1, n_x, n_y, 1]

    ’mask_brain’: Brain mask.

    torch.Tensor, shape [n_x, n_y]

    ’init_pred’: Initial prediction.

    torch.Tensor, shape [batch_size, 1, n_x, n_y, 2] or None

    ’target’: Target data.

    torch.Tensor, shape [batch_size, n_x, n_y] or None

    ’fname’: File name.

    str

    ’slice_num’: Slice number.

    int

    ’acc’: Acceleration factor of the sampling mask.

    float

  • batch_idx (Batch index.) – int

Returns

  • Dict[str, torch.Tensor], with keys,

  • ’loss’ (loss,) – torch.Tensor, shape [1]

  • ’log’ (log,) – dict, shape [1]

mridc.collections.quantitative.models.qcirim module

class mridc.collections.quantitative.models.qcirim.qCIRIM(cfg: DictConfig, trainer: Optional[Trainer] = None)[source]

Bases: BaseqMRIReconstructionModel, ABC

Implementation of the Cascades of Independently Recurrent Inference Machines, as presented in Karkalousos, D. et al.

References

Karkalousos, D. et al. (2021) ‘Assessment of Data Consistency through Cascades of Independently Recurrent Inference Machines for fast and robust accelerated MRI reconstruction’. Available at: https://arxiv.org/abs/2111.15498v1

allow_zero_length_dataloader_with_multiple_devices: bool
forward(R2star_map_init: Tensor, S0_map_init: Tensor, B0_map_init: Tensor, phi_map_init: Tensor, TEs: List, y: Tensor, sensitivity_maps: Tensor, mask_brain: Tensor, sampling_mask: Tensor) Union[Generator, Tensor][source]

Forward pass of the network.

Parameters
  • R2star_map_init (Initial R2* map.) – torch.Tensor, shape [batch_size, n_x, n_y]

  • S0_map_init (Initial S0 map.) – torch.Tensor, shape [batch_size, n_x, n_y]

  • B0_map_init (Initial B0 map.) – torch.Tensor, shape [batch_size, n_x, n_y]

  • phi_map_init (Initial phi map.) – torch.Tensor, shape [batch_size, n_x, n_y]

  • TEs (List of echo times.) – List of float, shape [n_echoes]

  • y (Data.) – torch.Tensor, shape [batch_size, n_echoes, n_coils, n_x, n_y, 2]

  • sensitivity_maps (Coil sensitivity maps.) – torch.Tensor, shape [batch_size, n_coils, n_x, n_y, 2]

  • mask_brain (Mask of the brain.) – torch.Tensor, shape [batch_size, 1, n_x, n_y, 2]

  • sampling_mask (Mask of the sampling.) – torch.Tensor, shape [batch_size, 1, n_x, n_y, 2]

Returns

pred – or torch.Tensor, shape [batch_size, n_x, n_y, 2] If self.accumulate_loss is True, returns a list of all intermediate estimates. If False, returns the final estimate.

Return type

list of list of torch.Tensor, shape [qmaps][batch_size, n_x, n_y, 2],

mse_vals: Dict
mse_vals_B0: Dict
mse_vals_R2star: Dict
mse_vals_S0: Dict
mse_vals_phi: Dict
mse_vals_reconstruction: Dict
nmse_vals: Dict
nmse_vals_B0: Dict
nmse_vals_R2star: Dict
nmse_vals_S0: Dict
nmse_vals_phi: Dict
nmse_vals_reconstruction: Dict
precision: int
prepare_data_per_node: bool
process_intermediate_pred(pred, sensitivity_maps, target, do_coil_combination=False)[source]

Process the intermediate prediction.

Parameters
  • pred (Intermediate prediction.) – torch.Tensor, shape [batch_size, n_coils, n_x, n_y, 2]

  • sensitivity_maps (Coil sensitivity maps.) – torch.Tensor, shape [batch_size, n_coils, n_x, n_y, 2]

  • target (Target data to crop to size.) – torch.Tensor, shape [batch_size, n_x, n_y, 2]

  • do_coil_combination (Whether to do coil combination.) – bool, default False

Returns

pred – Processed prediction.

Return type

torch.Tensor, shape [batch_size, n_x, n_y, 2]

process_quantitative_loss(target, pred, mask_brain, map, _loss_fn)[source]

Processes the loss.

Parameters
  • target (Target data.) – torch.Tensor, shape [batch_size, n_x, n_y, 2]

  • pred (Final prediction(s).) – list of torch.Tensor, shape [batch_size, n_x, n_y, 2], or torch.Tensor, shape [batch_size, n_x, n_y, 2]

  • mask_brain (Mask for brain.) – torch.Tensor, shape [batch_size, n_x, n_y, 1]

  • map (Type of map to regularize the loss.) – str in {“R2star”, “S0”, “B0”, “phi”}

  • _loss_fn (Loss function.) – torch.nn.Module, default torch.nn.L1Loss()

Returns

loss – If self.accumulate_loss is True, returns an accumulative result of all intermediate losses.

Return type

torch.FloatTensor, shape [1]

process_reconstruction_loss(target, pred, _loss_fn=None)[source]

Process the loss.

Parameters
  • target (Target data.) – torch.Tensor, shape [batch_size, n_x, n_y, 2]

  • pred (Final prediction(s).) – list of torch.Tensor, shape [batch_size, n_x, n_y, 2], or torch.Tensor, shape [batch_size, n_x, n_y, 2]

  • _loss_fn (Loss function.) – torch.nn.Module, default torch.nn.L1Loss()

Returns

loss – If self.accumulate_loss is True, returns an accumulative result of all intermediate losses.

Return type

torch.FloatTensor, shape [1]

psnr_vals: Dict
psnr_vals_B0: Dict
psnr_vals_R2star: Dict
psnr_vals_S0: Dict
psnr_vals_phi: Dict
psnr_vals_reconstruction: Dict
ssim_vals: Dict
ssim_vals_B0: Dict
ssim_vals_R2star: Dict
ssim_vals_S0: Dict
ssim_vals_phi: Dict
ssim_vals_reconstruction: Dict
training: bool

mridc.collections.quantitative.models.qvn module

class mridc.collections.quantitative.models.qvn.qVarNet(cfg: DictConfig, trainer: Optional[Trainer] = None)[source]

Bases: BaseqMRIReconstructionModel, ABC

Implementation of the quantitative End-to-end Variational Network (qVN), as presented in Zhang, C. et al.

References

Zhang, C. et al. (2022) ‘A unified model for reconstruction and R2 mapping of accelerated 7T data using quantitative Recurrent Inference Machine’. In review.

allow_zero_length_dataloader_with_multiple_devices: bool
forward(R2star_map_init: Tensor, S0_map_init: Tensor, B0_map_init: Tensor, phi_map_init: Tensor, TEs: List, y: Tensor, sensitivity_maps: Tensor, mask_brain: Tensor, sampling_mask: Tensor) List[Union[Tensor, List[Any]]][source]

Forward pass of the network.

Parameters
  • R2star_map_init (Initial R2* map.) – torch.Tensor, shape [batch_size, n_x, n_y]

  • S0_map_init (Initial S0 map.) – torch.Tensor, shape [batch_size, n_x, n_y]

  • B0_map_init (Initial B0 map.) – torch.Tensor, shape [batch_size, n_x, n_y]

  • phi_map_init (Initial phi map.) – torch.Tensor, shape [batch_size, n_x, n_y]

  • TEs (List of echo times.) – List of float, shape [n_echoes]

  • y (Data.) – torch.Tensor, shape [batch_size, n_echoes, n_coils, n_x, n_y, 2]

  • sensitivity_maps (Coil sensitivity maps.) – torch.Tensor, shape [batch_size, n_coils, n_x, n_y, 2]

  • mask_brain (Mask of the brain.) – torch.Tensor, shape [batch_size, 1, n_x, n_y, 2]

  • sampling_mask (Mask of the sampling.) – torch.Tensor, shape [batch_size, 1, n_x, n_y, 2]

Returns

pred – or torch.Tensor, shape [batch_size, n_x, n_y, 2] If self.accumulate_loss is True, returns a list of all intermediate estimates. If False, returns the final estimate.

Return type

list of list of torch.Tensor, shape [qmaps][batch_size, n_x, n_y, 2],

mse_vals: Dict
mse_vals_B0: Dict
mse_vals_R2star: Dict
mse_vals_S0: Dict
mse_vals_phi: Dict
mse_vals_reconstruction: Dict
nmse_vals: Dict
nmse_vals_B0: Dict
nmse_vals_R2star: Dict
nmse_vals_S0: Dict
nmse_vals_phi: Dict
nmse_vals_reconstruction: Dict
precision: int
prepare_data_per_node: bool
process_intermediate_pred(pred, sensitivity_maps, target, do_coil_combination=False)[source]

Process the intermediate prediction.

Parameters
  • pred (Intermediate prediction.) – torch.Tensor, shape [batch_size, n_coils, n_x, n_y, 2]

  • sensitivity_maps (Coil sensitivity maps.) – torch.Tensor, shape [batch_size, n_coils, n_x, n_y, 2]

  • target (Target data to crop to size.) – torch.Tensor, shape [batch_size, n_x, n_y, 2]

  • do_coil_combination (Whether to do coil combination.) – bool, default False

Returns

pred – Processed prediction.

Return type

torch.Tensor, shape [batch_size, n_x, n_y, 2]

psnr_vals: Dict
psnr_vals_B0: Dict
psnr_vals_R2star: Dict
psnr_vals_S0: Dict
psnr_vals_phi: Dict
psnr_vals_reconstruction: Dict
ssim_vals: Dict
ssim_vals_B0: Dict
ssim_vals_R2star: Dict
ssim_vals_S0: Dict
ssim_vals_phi: Dict
ssim_vals_reconstruction: Dict
training: bool

Module contents