Helper Module for Deep Learning.
Volume Tweening Network (VTN) and Affine and Dense Deformable Network (ADDNet) for Unsupervised medical Image Registration.
-
class
pynet.models.vtnet.ADDNet(input_shape, in_channels, kernel_size=3, padding=1, flow_multiplier=1.0)[source]¶ ADDNet.
Affine and Dense Deformable Network (ADDNet): affine registration subnetwork predicts a set of affine parameters, after which a flow field can be generated for warping.
Reference: https://arxiv.org/pdf/1902.05020. Code: https://github.com/microsoft/Recursive-Cascaded-Networks.
-
__init__(input_shape, in_channels, kernel_size=3, padding=1, flow_multiplier=1.0)[source]¶ Init class.
- Parameters
input_shape: uplet
the tensor data shape (X, Y, Z).
in_channels: int
number of channels in the input tensor.
kernel_size: int, default 3
the convolution kernels size (odd number).
padding: int, default 1
the padding size, recommended (kernel_size - 1) / 2
flow_multiplier: foat, default 1
weight the flow field by this factor.
-
affine_flow(affine, size, without_identity=False)[source]¶ Generates a flow field given an affine matrix.
- Parameters
affine: Tensor (N, 4, 4)
an affine transform.
size tuple
the target output image size.
without_identity: bool, defaul False
set to true if the identity matrix has already been substrated to the affine matrix.
- Returns
flow: Tensor
the generated affine flow field.
-
-
class
pynet.models.vtnet.ADDNetRegularizer(k1=0.1, k2=0.1, eps=1e-05)[source]¶ ADDNet Combined Regularization.
In addition to the correlation coefficient as our similarity loss, the orthogonality loss and the determinant loss are used as regularization losses for the affine network.
k1 * DetLoss + k2 * OrthoLoss
DetLoss: determinant should be close to 1, ie. reflection is not allowed. OrthoLoss: should be close to being orthogonal, ie. penalize the network for producing overly non-rigid transform. Let C=A’A, a positive semi-definite matrix should be close to I. For this, we require C has eigen values close to 1 by minimizing k1 + 1/k1 + k2 + 1/k2 + k3 + 1/k3. To prevent NaN, minimize k1 + eps + (1+eps)^2 / (k1+eps) + …
-
class
pynet.models.vtnet.VTNet(input_shape, in_channels, kernel_size=3, padding=1, flow_multiplier=1.0, nb_channels=16)[source]¶ VTNet.
Volume Tweening Network(VTN) consists of several cascaded registration subnetworks, after each of which the moving image is warped. The unsupervised training of network parameters is guided by the dissimilarity between the fixed image and each of the warped images, with the regularization losses on the flows predicted by the networks.
It follows an encoder-decoder architecture.
Reference: https://arxiv.org/pdf/1902.05020. Code: https://github.com/microsoft/Recursive-Cascaded-Networks.
-
__init__(input_shape, in_channels, kernel_size=3, padding=1, flow_multiplier=1.0, nb_channels=16)[source]¶ Init class.
- Parameters
input_shape: uplet
the tensor data shape (X, Y, Z).
in_channels: int
number of channels in the input tensor.
kernel_size: int, default 3
the convolution kernels size (odd number).
padding: int, default 1
the padding size, recommended (kernel_size - 1) / 2
flow_multiplier: foat, default 1
weight the flow field by this factor.
nb_channels: int, default 16
the number of channels after the first convolution.
-
-
pynet.models.vtnet.normal_transform_pixel(shape)[source]¶ Compute the normalization matrix from image size in pixels to [-1, 1].
-
pynet.models.vtnet.normalize_homography(affine, shape_src, shape_dst)[source]¶ Normalize a given homography in pixels to [-1, 1].
- Reference: https://discuss.pytorch.org/t/
affine-transformation-matrix-paramters-conversion/19522/13
- Parameters
affine: torch.Tensor (N, 4, 4)
homography/ies from source to destiantion to be normalized.
shape_src: tuple (3,)
size of the source image.
shape_dst: tuple (3,)
size of the destination image.
- Returns
affine: torch.Tensor (N, 4, 4)
the normalized homography/ies.
Follow us
Inspired by AZMIND template.