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- 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:
ModuleDefines 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:
ModuleLearned 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) – intchannels. (Input)
out_ch (
int) – intRIM. (Number of hidden channels in the)
channels (
Tuple[int,...]) – tuplee.g. (Dilations of the convolutional layers of the initializer. Typically it could be)
dilations (
Tuple[int,...]) – tuplee.g.
depth (RIM) – int
depth
multiscale_depth (
int) – 1output (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:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance 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:
ModuleRecurrent Inference Machine Module as in [1]_.
References:
[1] Putzky, Patrick, and Max Welling. “Recurrent Inference Machines for Solving Inverse Problems.” ArXiv:1706.04008 [Cs], June 2017. arXiv.org, http://arxiv.org/abs/1706.04008.
- __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) – CallableOperator. (Backward)
backward_operator (
Callable) – CallableOperator.
hidden_channels (
int) – intRIM. (Number of hidden channels in recurrent unit of)
x_channels (
int) – intDefault (Number of initializer multiscale. If "learned_initializer=False" this is ignored.) – 2 (complex data).
length (
int) – intDefault –
depth (
int) – intDefault
no_parameter_sharing (
bool) – boolFalse (If) – True.
Default – True.
instance_norm (
bool) – boolTrue (If) – False.
Default – False.
dense_connect (
bool) – boolDefault – False.
skip_connections (
bool) – boolTrue – True.
Default – True.
replication_padding (
bool) – boolDefaul (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) – boolTrue – 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) – intDefault
normalized (
bool) – boolTrue – class:NormConv2dGRU will be used instead of
Conv2dGRU. Default: False.
:param : class:NormConv2dGRU will be used instead of
Conv2dGRU. Default: False.
- 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.Tensorshape (Float tensor of)
masked_kspace (
Tensor) – torch.Tensorshape
sensitivity_map (
Optional[Tensor]) – torch.Tensorshape
sampling_mask (
Tensor) – torch.Tensorshape
previous_state (
Optional[Tensor]) – torch.Tensorloglikelihood_scaling (
Optional[Tensor]) – torch.Tensorshape
- 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:
MRIModelEngineRecurrent 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.