direct.nn.rim package#

Submodules#

direct.nn.rim.config module#

class direct.nn.rim.config.RIMConfig(model_name='???', engine_name=None, hidden_channels=16, length=8, depth=2, steps=1, no_parameter_sharing=False, instance_norm=False, dense_connect=False, whiten_input=False, replication_padding=True, image_initialization='zero_filled', scale_loglikelihood=None, learned_initializer=False, initializer_channels=(32, 32, 64, 64), initializer_dilations=(1, 1, 2, 4), initializer_multiscale=1, normalized=False)[source]#

Bases: ModelConfig

hidden_channels = 16#
length = 8#
depth = 2#
steps = 1#
no_parameter_sharing = False#
instance_norm = False#
dense_connect = False#
whiten_input = False#
replication_padding = True#
image_initialization = 'zero_filled'#
scale_loglikelihood = None#
learned_initializer = False#
initializer_channels = (32, 32, 64, 64)#
initializer_dilations = (1, 1, 2, 4)#
initializer_multiscale = 1#
normalized = False#
__init__(model_name='???', engine_name=None, hidden_channels=16, length=8, depth=2, steps=1, no_parameter_sharing=False, instance_norm=False, dense_connect=False, whiten_input=False, replication_padding=True, image_initialization='zero_filled', scale_loglikelihood=None, learned_initializer=False, initializer_channels=(32, 32, 64, 64), initializer_dilations=(1, 1, 2, 4), initializer_multiscale=1, normalized=False)#

direct.nn.rim.rim module#

class direct.nn.rim.rim.MRILogLikelihood(forward_operator, backward_operator)[source]#

Bases: Module

Defines the MRI loglikelihood assuming one noise vector for the complex images for all coils:

\[\frac{1}{\sigma^2} \sum_{i}^{N_c} {S}_i^{\text{H}} \mathcal{F}^{-1} P^{*} (P \mathcal{F} S_i x_{\tau} - y_{\tau})\]

for each time step \(\tau\).

__init__(forward_operator, backward_operator)[source]#

Inits MRILogLikelihood.

Parameters:
  • forward_operator (Callable) – Forward Operator.

  • backward_operator (Callable) – Backward Operator.

forward(input_image, masked_kspace, sensitivity_map, sampling_mask, loglikelihood_scaling=None)[source]#

Performs forward pass of MRILogLikelihood.

Parameters:
  • input_image – Initial or previous iteration of image with complex first of shape (N, complex, height, width).

  • masked_kspace – Masked k-space of shape (N, coil, height, width, complex).

  • sensitivity_map – Sensitivity Map of shape (N, coil, height, width, complex).

  • sampling_mask – Sampling mask.

  • loglikelihood_scaling – Multiplier for loglikelihood, for instance for the k-space noise, of shape (1,). Default: None.

Return type:

Tensor

Returns:

The MRI Loglikelihood.

class direct.nn.rim.rim.RIMInit(x_ch, out_ch, channels, dilations, depth=2, multiscale_depth=1)[source]#

Bases: Module

Learned initializer for RIM, based on multi-scale context aggregation with dilated convolutions, that replaces zero initializer for the RIM hidden vector. Inspired by [1]_.

References:

__init__(x_ch, out_ch, channels, dilations, depth=2, multiscale_depth=1)[source]#

Inits RIMInit.

Parameters:
  • x_ch (int) – int

  • channels. (Input)

  • out_ch (int) – int

  • RIM. (Number of hidden channels in the)

  • channels (Tuple[int, ...]) – tuple

  • e.g. (Dilations of the convolutional layers of the initializer. Typically it could be)

  • dilations (Tuple[int, ...]) – tuple

  • e.g.

  • depth (RIM) – int

  • depth

  • multiscale_depth (int) – 1

  • output (Number of feature layers to aggregate for the)

  • 1 (if)

  • disabled. (multi-scale context aggregation is)

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class direct.nn.rim.rim.RIM(forward_operator, backward_operator, hidden_channels, x_channels=2, length=8, depth=1, no_parameter_sharing=True, instance_norm=False, dense_connect=False, skip_connections=True, replication_padding=True, image_initialization='zero_filled', learned_initializer=False, initializer_channels=(32, 32, 64, 64), initializer_dilations=(1, 1, 2, 4), initializer_multiscale=1, normalized=False, **kwargs)[source]#

Bases: Module

Recurrent Inference Machine Module as in [1]_.

References:

__init__(forward_operator, backward_operator, hidden_channels, x_channels=2, length=8, depth=1, no_parameter_sharing=True, instance_norm=False, dense_connect=False, skip_connections=True, replication_padding=True, image_initialization='zero_filled', learned_initializer=False, initializer_channels=(32, 32, 64, 64), initializer_dilations=(1, 1, 2, 4), initializer_multiscale=1, normalized=False, **kwargs)[source]#

Inits RIM.

Parameters:
  • forward_operator (Callable) – Callable

  • Operator. (Backward)

  • backward_operator (Callable) – Callable

  • Operator.

  • hidden_channels (int) – int

  • RIM. (Number of hidden channels in recurrent unit of)

  • x_channels (int) – int

  • Default (Number of initializer multiscale. If "learned_initializer=False" this is ignored.) – 2 (complex data).

  • length (int) – int

  • Default

  • depth (int) – int

  • Default

  • no_parameter_sharing (bool) – bool

  • False (If) – True.

  • Default – True.

  • instance_norm (bool) – bool

  • True (If) – False.

  • Default – False.

  • dense_connect (bool) – bool

  • Default – False.

  • skip_connections (bool) – bool

  • True – True.

  • Default – True.

  • replication_padding (bool) – bool

  • Defaul (Replication padding for the recurrent unit of RIM.) – True.

  • image_initialization (str) – str

  • "sense" (Input image initialization for RIM. Can be) – “zero_filled”.

  • "input_kspace" – “zero_filled”.

  • Default – “zero_filled”.

  • learned_initializer (bool) – bool

  • True – False.

  • Default – False.

  • initializer_channels (Optional[Tuple[int, ...]]) – Optional[Tuple[int, …]]

  • Default – (32, 32, 64, 64).

  • initializer_dilations (Optional[Tuple[int, ...]]) – Optional[Tuple[int, …]]

  • "initialize_channels". (Number of dilations for learned_initializer. Must have the same length as)

  • Default – (1, 1, 2, 4)

  • initializer_multiscale (int) – int

  • Default

  • normalized (bool) – bool

  • True – class:NormConv2dGRU will be used instead of Conv2dGRU. Default: False.

:param : class:NormConv2dGRU will be used instead of Conv2dGRU. Default: False.

compute_sense_init(kspace, sensitivity_map)[source]#
Return type:

Tensor

forward(input_image, masked_kspace, sampling_mask, sensitivity_map=None, previous_state=None, loglikelihood_scaling=None, **kwargs)[source]#

Performs forward pass of RIM.

Parameters:
  • input_image (Tensor) – torch.Tensor

  • shape (Float tensor of)

  • masked_kspace (Tensor) – torch.Tensor

  • shape

  • sensitivity_map (Optional[Tensor]) – torch.Tensor

  • shape

  • sampling_mask (Tensor) – torch.Tensor

  • shape

  • previous_state (Optional[Tensor]) – torch.Tensor

  • loglikelihood_scaling (Optional[Tensor]) – torch.Tensor

  • shape

Returns:

torch.Tensor

direct.nn.rim.rim_engine module#

class direct.nn.rim.rim_engine.RIMEngine(cfg, model, device, forward_operator=None, backward_operator=None, mixed_precision=False, **models)[source]#

Bases: MRIModelEngine

Recurrent Inference Machine Engine.

__init__(cfg, model, device, forward_operator=None, backward_operator=None, mixed_precision=False, **models)[source]#

Inits RIMEngine.

Parameters:
  • cfg (BaseConfig) – Configuration file.

  • model (Module) – Model.

  • device (str) – Device. Can be “cuda: {idx}” or “cpu”.

  • forward_operator (Optional[Callable]) – The forward operator. Default: None.

  • backward_operator (Optional[Callable]) – The backward operator. Default: None.

  • mixed_precision (bool) – Use mixed precision. Default: False.

  • **models (Module) – Additional models.

Module contents#