cellmap_segmentation_challenge.models package#

Submodules#

cellmap_segmentation_challenge.models.model_load module#

cellmap_segmentation_challenge.models.model_load.load_latest(search_path, model)[source]#

Load the latest checkpoint from a directory into a model (in place).

Parameters:
  • search_path (str) – The path to search for checkpoints.

  • model (torch.nn.Module) – The model to load the checkpoint into.

cellmap_segmentation_challenge.models.model_load.load_best_val(logs_save_path, model_save_path, model, low_is_best=True)[source]#

Load the model weights with the best validation score from a directory into an existing model object in place.

Parameters:
  • logs_save_path (str) – The path to the directory with the tensorboard logs.

  • model_save_path (str) – The path to the model checkpoints.

  • model (torch.nn.Module) – The model to load the checkpoint into.

  • low_is_best (bool) – Whether a lower validation score is better.

cellmap_segmentation_challenge.models.resnet module#

class cellmap_segmentation_challenge.models.resnet.Resnet2D(input_nc=1, output_nc=None, ngf=64, norm_layer=<class 'torch.nn.modules.instancenorm.InstanceNorm2d'>, use_dropout=False, n_blocks=6, padding_type='reflect', activation=<class 'torch.nn.modules.activation.ReLU'>, n_downsampling=2)[source]#

Bases: Module

Construct a Resnet :param input_nc: :type input_nc: int :param output_nc: :type output_nc: int) – the number of channels in output images (default is ngf :param ngf: :type ngf: int :param norm_layer – normalization layer: :param use_dropout: :type use_dropout: bool :param n_blocks: :type n_blocks: int :param padding_type: reflect | replicate | zeros | valid :type padding_type: str :param activation – non-linearity layer to apply: :type activation – non-linearity layer to apply: default is ReLU :param n_downsampling – number of times to downsample data before ResBlocks:

forward(input)[source]#

Standard forward

class cellmap_segmentation_challenge.models.resnet.ResnetBlock2D(dim, padding_type, norm_layer, use_dropout, use_bias, activation=<class 'torch.nn.modules.activation.ReLU'>)[source]#

Bases: Module

Initialize the Resnet block A resnet block is a conv block with skip connections We construct a conv block with build_conv_block function, and implement skip connections in <forward> function. Original Resnet paper: https://arxiv.org/pdf/1512.03385.pdf

build_conv_block(dim, padding_type, norm_layer, use_dropout, use_bias, activation=<class 'torch.nn.modules.activation.ReLU'>)[source]#

Construct a convolutional block. :param dim: :type dim: int :param padding_type: reflect | replicate | zeros | valid :type padding_type: str :param norm_layer – normalization layer: :param use_dropout: :type use_dropout: bool :param use_bias: :type use_bias: bool :param activation – non-linearity layer to apply: :type activation – non-linearity layer to apply: default is ReLU

Returns a conv block (with a conv layer, a normalization layer, and a non-linearity layer)

crop(x, shape)[source]#

Center-crop x to match spatial dimensions given by shape.

forward(x)[source]#

Forward function (with skip connections)

class cellmap_segmentation_challenge.models.resnet.Resnet3D(input_nc=1, output_nc=None, ngf=64, norm_layer=<class 'torch.nn.modules.instancenorm.InstanceNorm3d'>, use_dropout=False, n_blocks=6, padding_type='reflect', activation=<class 'torch.nn.modules.activation.ReLU'>, n_downsampling=2)[source]#

Bases: Module

Construct a Resnet :param input_nc: :type input_nc: int :param output_nc: :type output_nc: int :param ngf: :type ngf: int :param norm_layer – normalization layer: :param use_dropout: :type use_dropout: bool :param n_blocks: :type n_blocks: int :param padding_type: reflect | replicate | zeros | valid :type padding_type: str :param activation – non-linearity layer to apply: :type activation – non-linearity layer to apply: default is ReLU :param n_downsampling – number of times to downsample data before ResBlocks:

forward(input)[source]#

Standard forward

class cellmap_segmentation_challenge.models.resnet.ResnetBlock3D(dim, padding_type, norm_layer, use_dropout, use_bias, activation=<class 'torch.nn.modules.activation.ReLU'>)[source]#

Bases: Module

Initialize the Resnet block A resnet block is a conv block with skip connections We construct a conv block with build_conv_block function, and implement skip connections in <forward> function. Original Resnet paper: https://arxiv.org/pdf/1512.03385.pdf

build_conv_block(dim, padding_type, norm_layer, use_dropout, use_bias, activation=<class 'torch.nn.modules.activation.ReLU'>)[source]#

Construct a convolutional block. :param dim: :type dim: int :param padding_type: reflect | replicate | zeros | valid :type padding_type: str :param norm_layer – normalization layer: :param use_dropout: :type use_dropout: bool :param use_bias: :type use_bias: bool :param activation – non-linearity layer to apply: :type activation – non-linearity layer to apply: default is ReLU

Returns a conv block (with a conv layer, a normalization layer, and a non-linearity layer)

crop(x, shape)[source]#

Center-crop x to match spatial dimensions given by shape.

forward(x)[source]#

Forward function (with skip connections)

class cellmap_segmentation_challenge.models.resnet.ResNet(ndims, **kwargs)[source]#

Bases: Resnet2D, Resnet3D

Construct a Resnet :param input_nc: :type input_nc: int :param output_nc: :type output_nc: int) – the number of channels in output images (default is ngf :param ngf: :type ngf: int :param norm_layer – normalization layer: :param use_dropout: :type use_dropout: bool :param n_blocks: :type n_blocks: int :param padding_type: reflect | replicate | zeros | valid :type padding_type: str :param activation – non-linearity layer to apply: :type activation – non-linearity layer to apply: default is ReLU :param n_downsampling – number of times to downsample data before ResBlocks:

cellmap_segmentation_challenge.models.unet_model_2D module#

Parts of the U-Net model

class cellmap_segmentation_challenge.models.unet_model_2D.DoubleConv(in_channels, out_channels, mid_channels=None)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.unet_model_2D.Down(in_channels, out_channels)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.unet_model_2D.Up(in_channels, out_channels, bilinear=True)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x1, x2)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.unet_model_2D.OutConv(in_channels, out_channels)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.unet_model_2D.UNet_2D(n_channels, n_classes, trilinear=False)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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.

cellmap_segmentation_challenge.models.unet_model_3D module#

Parts of the U-Net model

class cellmap_segmentation_challenge.models.unet_model_3D.DoubleConv(in_channels, out_channels, mid_channels=None)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.unet_model_3D.Down(in_channels, out_channels)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.unet_model_3D.Up(in_channels, out_channels, trilinear=True)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x1, x2)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.unet_model_3D.OutConv(in_channels, out_channels)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.unet_model_3D.UNet_3D(n_channels, n_classes, trilinear=False)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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.

cellmap_segmentation_challenge.models.vitnet module#

cellmap_segmentation_challenge.models.vitnet.get_3DReg_config()[source]#
cellmap_segmentation_challenge.models.vitnet.np2th(weights, conv=False)[source]#

Possibly convert HWIO to OIHW.

cellmap_segmentation_challenge.models.vitnet.swish(x)[source]#
class cellmap_segmentation_challenge.models.vitnet.Attention(config, vis)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

transpose_for_scores(x)[source]#
forward(hidden_states)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.vitnet.Mlp(config)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.vitnet.Embeddings(config, img_size)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.vitnet.Block(config, vis)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.vitnet.Encoder(config, vis)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(hidden_states)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.vitnet.Transformer(config, img_size, vis)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(input_ids)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.vitnet.Conv3dReLU(in_channels, out_channels, kernel_size, padding=0, stride=1, use_batchnorm=True)[source]#

Bases: Sequential

Initialize internal Module state, shared by both nn.Module and ScriptModule.

class cellmap_segmentation_challenge.models.vitnet.DecoderBlock(in_channels, out_channels, skip_channels=0, use_batchnorm=True)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x, skip=None)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.vitnet.DecoderCup(config, img_size)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(hidden_states, features=None)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.vitnet.DoubleConv(in_channels, out_channels, mid_channels=None)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.vitnet.Down(in_channels, out_channels)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.vitnet.CNNEncoder(config, n_channels=2)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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 cellmap_segmentation_challenge.models.vitnet.RegistrationHead(in_channels, out_channels, kernel_size=3, upsampling=1)[source]#

Bases: Sequential

Initialize internal Module state, shared by both nn.Module and ScriptModule.

class cellmap_segmentation_challenge.models.vitnet.ViTVNet(out_channels, config='ViT-V-Net', img_size=(128, 128, 128), vis=False)[source]#

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

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.

Module contents#