pymic.net.net2d package

Submodules

pymic.net.net2d.cople_net module

class pymic.net.net2d.cople_net.ASPPBlock(in_channels, out_channels_list, kernel_size_list, dilation_list)

Bases: Module

ASPP block.

forward(x)

Defines 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.

training: bool
class pymic.net.net2d.cople_net.COPLENet(params)

Bases: Module

Implementation of of COPLENet for COVID-19 pneumonia lesion segmentation from CT images.

Parameters are given in the params dictionary, and should include the following fields:

Parameters:
  • in_chns – (int) Input channel number.

  • feature_chns – (list) Feature channel for each resolution level. The length should be 5, such as [16, 32, 64, 128, 256].

  • dropout – (list) The dropout ratio for each resolution level. The length should be the same as that of feature_chns.

  • class_num – (int) The class number for segmentation task.

  • bilinear – (bool) Using bilinear for up-sampling or not. If False, deconvolution will be used for up-sampling.

forward(x)

Defines 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.

training: bool
class pymic.net.net2d.cople_net.ConvBNActBlock(in_channels, out_channels, dropout_p)

Bases: Module

Two convolution layers with batch norm, leaky relu, dropout and SE block.

forward(x)

Defines 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.

training: bool
class pymic.net.net2d.cople_net.ConvLayer(in_channels, out_channels, kernel_size=1)

Bases: Module

A combination of Conv2d, BatchNorm2d and LeakyReLU.

forward(x)

Defines 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.

training: bool
class pymic.net.net2d.cople_net.DownBlock(in_channels, out_channels, dropout_p)

Bases: Module

Downsampling by a concantenation of max-pool and avg-pool, followed by ConvBNActBlock.

forward(x)

Defines 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.

training: bool
class pymic.net.net2d.cople_net.SEBlock(in_channels, r)

Bases: Module

A Modified Squeeze-and-Excitation block for spatial attention.

forward(x)

Defines 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.

training: bool
class pymic.net.net2d.cople_net.UpBlock(in_channels1, in_channels2, out_channels, bilinear=True, dropout_p=0.5)

Bases: Module

Upssampling followed by ConvBNActBlock.

forward(x1, x2)

Defines 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.

training: bool

pymic.net.net2d.scse2d module

2D implementation of:

  1. Channel Squeeze and Excitation

  2. Spatial Squeeze and Excitation

  3. Concurrent Spatial and Channel Squeeze & Excitation

Oringinal file is on Github.

class pymic.net.net2d.scse2d.ChannelSELayer(num_channels, reduction_ratio=2)

Bases: Module

Re-implementation of Squeeze-and-Excitation (SE) block.

  • Reference: Jie Hu, Li Shen, Gang Sun: Squeeze-and-Excitation Networks. CVPR 2018.

Parameters:
  • num_channels – Number of input channels

  • reduction_ratio – By how much should the num_channels should be reduced.

forward(input_tensor)
Parameters:

input_tensor – X, shape = (batch_size, num_channels, H, W)

Returns:

output tensor

training: bool
class pymic.net.net2d.scse2d.ChannelSpatialSELayer(num_channels, reduction_ratio=2)

Bases: Module

Re-implementation of concurrent spatial and channel squeeze & excitation.

  • Reference: Roy et al., Concurrent Spatial and Channel Squeeze & Excitation in Fully Convolutional Networks, MICCAI 2018.

Parameters:
  • num_channels – Number of input channels.

  • reduction_ratio – By how much should the num_channels should be reduced.

forward(input_tensor)
Parameters:

input_tensor – X, shape = (batch_size, num_channels, H, W)

Returns:

output_tensor

training: bool
class pymic.net.net2d.scse2d.SELayer(value)

Bases: Enum

Enum restricting the type of SE Blockes available. So that type checking can be adding when adding these blockes to a neural network:

if self.se_block_type == se.SELayer.CSE.value:
    self.SELayer = se.ChannelSpatialSELayer(params['num_filters'])
elif self.se_block_type == se.SELayer.SSE.value:
    self.SELayer = se.SpatialSELayer(params['num_filters'])
elif self.se_block_type == se.SELayer.CSSE.value:
    self.SELayer = se.ChannelSpatialSELayer(params['num_filters'])
CSE = 'CSE'
CSSE = 'CSSE'
NONE = 'NONE'
SSE = 'SSE'
class pymic.net.net2d.scse2d.SpatialSELayer(num_channels)

Bases: Module

Re-implementation of SE block – squeezing spatially and exciting channel-wise.

  • Reference: Roy et al., Concurrent Spatial and Channel Squeeze & Excitation in Fully Convolutional Networks, MICCAI 2018.

Parameters:

num_channels – Number of input channels.

forward(input_tensor, weights=None)
Parameters:
  • weights – weights for few shot learning

  • input_tensor – X, shape = (batch_size, num_channels, H, W)

Returns:

output_tensor

training: bool

pymic.net.net2d.unet2d module

class pymic.net.net2d.unet2d.ConvBlock(in_channels, out_channels, dropout_p)

Bases: Module

Two convolution layers with batch norm and leaky relu. Droput is used between the two convolution layers.

Parameters:
  • in_channels – (int) Input channel number.

  • out_channels – (int) Output channel number.

  • dropout_p – (int) Dropout probability.

forward(x)

Defines 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.

training: bool
class pymic.net.net2d.unet2d.Decoder(params)

Bases: Module

Decoder of 2D UNet.

Parameters are given in the params dictionary, and should include the following fields:

Parameters:
  • in_chns – (int) Input channel number.

  • feature_chns – (list) Feature channel for each resolution level. The length should be 4 or 5, such as [16, 32, 64, 128, 256].

  • dropout – (list) The dropout ratio for each resolution level. The length should be the same as that of feature_chns.

  • class_num – (int) The class number for segmentation task.

  • bilinear – (bool) Using bilinear for up-sampling or not. If False, deconvolution will be used for up-sampling.

forward(x)

Defines 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.

training: bool
class pymic.net.net2d.unet2d.DownBlock(in_channels, out_channels, dropout_p)

Bases: Module

Downsampling followed by ConvBlock

Parameters:
  • in_channels – (int) Input channel number.

  • out_channels – (int) Output channel number.

  • dropout_p – (int) Dropout probability.

forward(x)

Defines 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.

training: bool
class pymic.net.net2d.unet2d.Encoder(params)

Bases: Module

Encoder of 2D UNet.

Parameters are given in the params dictionary, and should include the following fields:

Parameters:
  • in_chns – (int) Input channel number.

  • feature_chns – (list) Feature channel for each resolution level. The length should be 4 or 5, such as [16, 32, 64, 128, 256].

  • dropout – (list) The dropout ratio for each resolution level. The length should be the same as that of feature_chns.

forward(x)

Defines 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.

training: bool
class pymic.net.net2d.unet2d.UNet2D(params)

Bases: Module

An implementation of 2D U-Net.

  • Reference: Olaf Ronneberger, Philipp Fischer, Thomas Brox: U-Net: Convolutional Networks for Biomedical Image Segmentation. MICCAI (3) 2015: 234-241

Note that there are some modifications from the original paper, such as the use of batch normalization, dropout, leaky relu and deep supervision.

Parameters are given in the params dictionary, and should include the following fields:

Parameters:
  • in_chns – (int) Input channel number.

  • feature_chns – (list) Feature channel for each resolution level. The length should be 4 or 5, such as [16, 32, 64, 128, 256].

  • dropout – (list) The dropout ratio for each resolution level. The length should be the same as that of feature_chns.

  • class_num – (int) The class number for segmentation task.

  • bilinear – (bool) Using bilinear for up-sampling or not. If False, deconvolution will be used for up-sampling.

  • multiscale_pred – (bool) Get multiscale prediction.

forward(x)

Defines 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.

training: bool
class pymic.net.net2d.unet2d.UpBlock(in_channels1, in_channels2, out_channels, dropout_p, bilinear=True)

Bases: Module

Upsampling followed by ConvBlock

Parameters:
  • in_channels1 – (int) Channel number of high-level features.

  • in_channels2 – (int) Channel number of low-level features.

  • out_channels – (int) Output channel number.

  • dropout_p – (int) Dropout probability.

  • bilinear – (bool) Use bilinear for up-sampling (by default). If False, deconvolution is used for up-sampling.

forward(x1, x2)

Defines 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.

training: bool

pymic.net.net2d.unet2d_attention module

class pymic.net.net2d.unet2d_attention.AttentionGateBlock(chns_l, chns_h)

Bases: Module

forward(x_l, x_h)

Defines 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.

training: bool
class pymic.net.net2d.unet2d_attention.AttentionUNet2D(params)

Bases: UNet2D

training: bool
class pymic.net.net2d.unet2d_attention.UpBlockWithAttention(in_channels1, in_channels2, out_channels, dropout_p, bilinear=True)

Bases: Module

Upsampling followed by ConvBlock

forward(x1, x2)

Defines 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.

training: bool

pymic.net.net2d.unet2d_cct module

class pymic.net.net2d.unet2d_cct.AuxiliaryDecoder(params, aux_type)

Bases: Module

An Auxiliary Decoder. aux_type should be one of {DropOut, FeatureDrop, FeatureNoise and VAT}. Other parameters for the decoder are given in the params dictionary, see pymic.net.net2d.unet2d.Decoder for details. In addition, the following fields are needed for pertubation:

Parameters:
  • Uniform_range – (float) The range of noise. Only needed when aux_type`=`FeatureNoise.

  • VAT_it – (float) The iteration number of VAT. Only needed when aux_type`=`VAT.

  • VAT_xi – (float) The hyper-parameter xi of VAT. Only needed when aux_type`=`VAT.

  • VAT_eps – (float) The hyper-parameter eps of VAT. Only needed when aux_type`=`VAT.

feature_based_noise(x)
feature_drop(x)
forward(x)

Defines 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.

training: bool
class pymic.net.net2d.unet2d_cct.UNet2D_CCT(params)

Bases: Module

An modification the U-Net with auxiliary decoders according to the CCT paper.

  • Reference: Yassine Ouali, Celine Hudelot and Myriam Tami: Semi-Supervised Semantic Segmentation With Cross-Consistency Training. CVPR 2020.

Code adapted from Github.

Parameter for the network backbone are given in the params dictionary, see pymic.net.net2d.unet2d.UNet2D for details. In addition, the following fields are needed for pertubation in the auxiliary decoders:

Parameters:

CCT_aux_decoders – (list) A list of auxiliary decoder types. Supported values are {DropOut, FeatureDrop, FeatureNoise and VAT}.

The parameters for different types of auxiliary decoders should also be given in the params dictionary, see pymic.net.net2d.unet2d_cct.AuxiliaryDecoder for details.

forward(x)

Defines 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.

training: bool

pymic.net.net2d.unet2d_dual_branch module

class pymic.net.net2d.unet2d_dual_branch.UNet2D_DualBranch(params)

Bases: Module

A dual branch network using UNet2D as backbone.

  • Reference: Xiangde Luo, Minhao Hu, Wenjun Liao, Shuwei Zhai, Tao Song, Guotai Wang, Shaoting Zhang. ScribblScribble-Supervised Medical Image Segmentation via Dual-Branch Network and Dynamically Mixed Pseudo Labels Supervision. MICCAI 2022.

The parameters for the backbone should be given in the params dictionary. See pymic.net.net2d.unet2d.UNet2D for details. In addition, the following field should be included:

Parameters:

output_mode – (str) How to obtain the result during the inference. average: taking average of the two branches. first: takeing the result in the first branch. second: taking the result in the second branch.

forward(x)

Defines 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.

training: bool

pymic.net.net2d.unet2d_nest module

class pymic.net.net2d.unet2d_nest.NestedUNet2D(params)

Bases: Module

An implementation of the Nested U-Net.

Note that there are some modifications from the original paper, such as the use of dropout and leaky relu here.

Parameters are given in the params dictionary, and should include the following fields:

Parameters:
  • in_chns – (int) Input channel number.

  • feature_chns – (list) Feature channel for each resolution level. The length should be 4 or 5, such as [16, 32, 64, 128, 256].

  • dropout – (list) The dropout ratio for each resolution level. The length should be the same as that of feature_chns.

  • class_num – (int) The class number for segmentation task.

forward(x)

Defines 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.

training: bool

pymic.net.net2d.unet2d_scse module

class pymic.net.net2d.unet2d_scse.ConvScSEBlock(in_channels, out_channels, dropout_p)

Bases: Module

Two convolutional blocks followed by ChannelSpatialSELayer. Each block consists of Conv2d + BatchNorm2d + LeakyReLU. A dropout layer is used between the wo blocks.

Parameters:
  • in_channels – (int) Input channel number.

  • out_channels – (int) Output channel number.

  • dropout_p – (int) Dropout probability.

forward(x)

Defines 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.

training: bool
class pymic.net.net2d.unet2d_scse.DownBlock(in_channels, out_channels, dropout_p)

Bases: Module

Downsampling followed by ConvScSEBlock.

Parameters:
  • in_channels – (int) Input channel number.

  • out_channels – (int) Output channel number.

  • dropout_p – (int) Dropout probability.

forward(x)

Defines 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.

training: bool
class pymic.net.net2d.unet2d_scse.UNet2D_ScSE(params)

Bases: Module

Combining 2D U-Net with SCSE module.

Parameters are given in the params dictionary, and should include the following fields:

Parameters:
  • in_chns – (int) Input channel number.

  • feature_chns – (list) Feature channel for each resolution level. The length should be 5, such as [16, 32, 64, 128, 256].

  • dropout – (list) The dropout ratio for each resolution level. The length should be the same as that of feature_chns.

  • class_num – (int) The class number for segmentation task.

  • bilinear – (bool) Using bilinear for up-sampling or not. If False, deconvolution will be used for up-sampling.

forward(x)

Defines 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.

training: bool
class pymic.net.net2d.unet2d_scse.UpBlock(in_channels1, in_channels2, out_channels, dropout_p, bilinear=True)

Bases: Module

Up-sampling followed by ConvScSEBlock in U-Net structure.

Parameters:
  • in_channels1 – (int) Input channel number for low-resolution feature map.

  • in_channels2 – (int) Input channel number for high-resolution feature map.

  • out_channels – (int) Output channel number.

  • dropout_p – (int) Dropout probability.

  • bilinear – (bool) Use bilinear for up-sampling or not.

forward(x1, x2)

Defines 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.

training: bool

pymic.net.net2d.unet2d_urpc module

Module contents