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:
ModuleASPP 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net2d.cople_net.COPLENet(params)
Bases:
ModuleImplementation of of COPLENet for COVID-19 pneumonia lesion segmentation from CT images.
Reference: G. Wang et al. A Noise-robust Framework for Automatic Segmentation of COVID-19 Pneumonia Lesions from CT Images. IEEE Transactions on Medical Imaging, 39(8),2020:2653-2663.
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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net2d.cople_net.ConvBNActBlock(in_channels, out_channels, dropout_p)
Bases:
ModuleTwo 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net2d.cople_net.ConvLayer(in_channels, out_channels, kernel_size=1)
Bases:
ModuleA 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net2d.cople_net.DownBlock(in_channels, out_channels, dropout_p)
Bases:
ModuleDownsampling 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net2d.cople_net.SEBlock(in_channels, r)
Bases:
ModuleA 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net2d.cople_net.UpBlock(in_channels1, in_channels2, out_channels, bilinear=True, dropout_p=0.5)
Bases:
ModuleUpssampling 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
pymic.net.net2d.scse2d module
2D implementation of:
Channel Squeeze and Excitation
Spatial Squeeze and Excitation
Concurrent Spatial and Channel Squeeze & Excitation
Oringinal file is on Github.
- class pymic.net.net2d.scse2d.ChannelSELayer(num_channels, reduction_ratio=2)
Bases:
ModuleRe-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
- class pymic.net.net2d.scse2d.ChannelSpatialSELayer(num_channels, reduction_ratio=2)
Bases:
ModuleRe-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
- class pymic.net.net2d.scse2d.SELayer(value)
Bases:
EnumEnum 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:
ModuleRe-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
pymic.net.net2d.unet2d module
- class pymic.net.net2d.unet2d.ConvBlock(in_channels, out_channels, dropout_p)
Bases:
ModuleTwo 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net2d.unet2d.Decoder(params)
Bases:
ModuleDecoder 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net2d.unet2d.DownBlock(in_channels, out_channels, dropout_p)
Bases:
ModuleDownsampling 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net2d.unet2d.Encoder(params)
Bases:
ModuleEncoder 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net2d.unet2d.UNet2D(params)
Bases:
ModuleAn 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net2d.unet2d.UpBlock(in_channels1, in_channels2, out_channels, dropout_p, bilinear=True)
Bases:
ModuleUpsampling 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net2d.unet2d_attention.UpBlockWithAttention(in_channels1, in_channels2, out_channels, dropout_p, bilinear=True)
Bases:
ModuleUpsampling 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
pymic.net.net2d.unet2d_cct module
- class pymic.net.net2d.unet2d_cct.AuxiliaryDecoder(params, aux_type)
Bases:
ModuleAn 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.Decoderfor 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net2d.unet2d_cct.UNet2D_CCT(params)
Bases:
ModuleAn 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.UNet2Dfor 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.AuxiliaryDecoderfor 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
pymic.net.net2d.unet2d_dual_branch module
- class pymic.net.net2d.unet2d_dual_branch.UNet2D_DualBranch(params)
Bases:
ModuleA 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.UNet2Dfor 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
pymic.net.net2d.unet2d_nest module
- class pymic.net.net2d.unet2d_nest.NestedUNet2D(params)
Bases:
ModuleAn implementation of the Nested U-Net.
Reference: Zongwei Zhou, et al.: UNet++: A Nested U-Net Architecture for Medical Image Segmentation. MICCAI DLMIA workshop, 2018: 3-11.
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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
pymic.net.net2d.unet2d_scse module
- class pymic.net.net2d.unet2d_scse.ConvScSEBlock(in_channels, out_channels, dropout_p)
Bases:
ModuleTwo 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net2d.unet2d_scse.DownBlock(in_channels, out_channels, dropout_p)
Bases:
ModuleDownsampling 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net2d.unet2d_scse.UNet2D_ScSE(params)
Bases:
ModuleCombining 2D U-Net with SCSE module.
Reference: Abhijit Guha Roy, Nassir Navab, Christian Wachinger: Recalibrating Fully Convolutional Networks With Spatial and Channel “Squeeze and Excitation” Blocks. IEEE Trans. Med. Imaging 38(2): 540-549 (2019).
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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net2d.unet2d_scse.UpBlock(in_channels1, in_channels2, out_channels, dropout_p, bilinear=True)
Bases:
ModuleUp-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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.