unet
Module containing UNet models. Most code from https://github.com/milesial/Pytorch-UNet
- class DoubleConv(in_channels: int, out_channels: int, mid_channels: int | None = None)
Applies a double convolution to the input
(convolution => [BN] => ReLU) * 2
Adapted from https://github.com/milesial/Pytorch-UNet for
minerva
.- Parameters:
- class Down(in_channels: int, out_channels: int)
Downscaling with maxpool then double convolution.
Adapted from https://github.com/milesial/Pytorch-UNet for
minerva
.- maxpool_conv
Sequential
ofMaxPool2d
thenDoubleConv
.- Type:
- Parameters:
- class OutConv(in_channels: int, out_channels: int)
1x1
convolution to change the number of channels down of the input.Adapted from https://github.com/milesial/Pytorch-UNet for
minerva
.- Parameters:
- class UNet(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, bilinear: bool = False, scaler: GradScaler | None = None)
UNet model. Good for segmentation problems.
Adapted from https://github.com/milesial/Pytorch-UNet for use in
minerva
.- inc
Double convolutional layers as input to the network to 64 channels.
- Type:
- Parameters:
- class UNetR(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, bilinear: bool = False, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})
UNet model which incorporates a
ResNet
as the encoder.- backbone
Backbone of the FCN that takes the imagery input and extracts learned representations.
- Type:
- Parameters:
criterion –
torch
loss function model will use.input_size (tuple[int, ...]) – Optional; Defines the shape of the input data in order of number of channels, image width, image height.
n_classes (int) – Optional; Number of classes in data to be classified.
bilinear (bool) – Optional;
backbone_name (str) – Optional; Name of the backbone within this module to use for the UNet.
backbone_weight_path (str) – Optional; Path to pre-trained weights for the backbone to be loaded.
freeze_backbone (bool) – Freezes the weights on the backbone to prevent end-to-end training if using a pre-trained backbone.
backbone_kwargs (dict[str, Any]) – Optional; Keyword arguments for the backbone packed up into a dict.
- forward(x: Tensor) Tensor
Performs a forward pass of the UNet using
backbone
.Passes the input tensor to the
backbone
. Then passes the output tensors from the resnet residual blocks to corresponding stages of the decoder, upsampling to create an output with the same spatial size as the input size.
- class UNetR101(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, bilinear: bool = False, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})
UNet with a
ResNet101
as the backbone.
- class UNetR152(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, bilinear: bool = False, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})
UNet with a
ResNet152
as the backbone.
- class UNetR18(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, bilinear: bool = False, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})
UNet with a
ResNet18
as the backbone.
- class UNetR34(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, bilinear: bool = False, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})
UNet with a
ResNet34
as the backbone.
- class UNetR50(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, bilinear: bool = False, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})
UNet with a
ResNet50
as the backbone.
- class Up(in_channels: int, out_channels: int, bilinear: bool = True)
Upscaling then double convolution.
Adapted from https://github.com/milesial/Pytorch-UNet for use in
minerva
.- conv
Double convolutional layers.
- Type:
- Parameters:
- forward(x1: Tensor, x2: Tensor) Tensor
Applies upscaling to
x1
, concatsx1
withx2
then appliesDoubleConv
to the result.- Parameters:
x1 (Tensor) – Input tensor 1 to be upscaled to match
x2
.x2 (Tensor) – Input tensor 2 to be concated with upscaled
x1
and passed throughDoubleConv
.
- Returns:
Output tensor of the the upscaling and double convolutions.
- Return type: