AD phase reconstruction

Automatic differentiation (AD) based methods of phase reconstruction.

AD phase reconstruction

Deep image prior model

class PyLorentz.phase.DIP_NN.DIP_NN(*args: Any, **kwargs: Any)[source]

Bases: Module

Autoencoder for reconstructing object wave and amplitude of LTEM images.

Parameters:
  • num_images – int, number of input channels, equal to number of images in TFS.

  • nb_filters – int, number of filters in the first convolutional block.

  • use_dropout – bool, whether to use dropout in the inner layers.

  • batch_norm – bool, whether to use batch normalization after each convolutional layer.

  • upsampling_mode – str, “bilinear” or “nearest” upsampling method.

__init__(num_images: int = 1, nb_filters: int = 16, use_dropout: bool = False, batch_norm: bool = False, upsampling_mode: str = 'nearest')[source]
forward(x: torch.Tensor) torch.Tensor[source]

Forward pass for the DIP network.

Parameters:

x – Input tensor.

Returns:

Output tensor after passing through the network.

class PyLorentz.phase.DIP_NN.conv2dblock(*args: Any, **kwargs: Any)[source]

Bases: Module

A block consisting of convolutional layers with optional batch normalization and dropout.

Parameters:
  • nb_layers – int, number of convolutional layers.

  • input_channels – int, number of input channels.

  • output_channels – int, number of output channels.

  • kernel_size – int, size of the convolutional kernel.

  • stride – int, stride of the convolution.

  • padding – int, padding for the convolution.

  • use_batchnorm – bool, whether to use batch normalization.

  • lrelu_a – float, negative slope for the Leaky ReLU activation.

  • dropout – float, dropout rate.

  • last_sigmoid – bool, whether to use a sigmoid activation on the last layer.

  • last_tanh – bool, whether to use a tanh activation on the last layer.

  • last_skipReLU – bool, whether to skip ReLU activation on the last layer.

__init__(nb_layers: int, input_channels: int, output_channels: int, kernel_size: int = 3, stride: int = 1, padding: int = 1, use_batchnorm: bool = False, lrelu_a: float = 0.01, dropout_: float = 0, last_sigmoid: bool = False, last_tanh: bool = False, last_skipReLU: bool = False)[source]
forward(x: torch.Tensor) torch.Tensor[source]

Forward pass for the conv2dblock.

Parameters:

x – Input tensor.

Returns:

Output tensor after passing through the block.

class PyLorentz.phase.DIP_NN.upsample_block(*args: Any, **kwargs: Any)[source]

Bases: Module

Upsampling block using interpolation followed by a convolution.

Parameters:
  • input_channels – int, number of input channels.

  • output_channels – int, number of output channels.

  • scale_factor – int, factor by which to scale the input.

  • mode – str, interpolation mode, either “bilinear” or “nearest”.

__init__(input_channels: int, output_channels: int, scale_factor: int = 2, mode: str = 'bilinear')[source]
forward(x: torch.Tensor) torch.Tensor[source]

Forward pass for the upsample_block.

Parameters:

x – Input tensor.

Returns:

Output tensor after upsampling and convolution.

PyLorentz.phase.DIP_NN.rng_seed(seed: int) None[source]

Set the random seed for reproducibility.

Parameters:

seed – The seed value to use.

Returns:

None

PyLorentz.phase.DIP_NN.weight_reset(m: torch.nn.Module) None[source]

Reset the weights of a given module.

Parameters:

m – The neural network module to reset.

Returns:

None