pymic.net.net3d package
Submodules
pymic.net.net3d.scse3d module
3D implementation of:
Channel Squeeze and Excitation
Spatial Squeeze and Excitation
Concurrent Spatial and Channel Squeeze & Excitation
Oringinal file is on Github.
- class pymic.net.net3d.scse3d.ChannelSELayer3D(num_channels, reduction_ratio=2)
Bases:
Module3D 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, D, H, W)
- Returns:
output tensor
- class pymic.net.net3d.scse3d.ChannelSpatialSELayer3D(num_channels, reduction_ratio=2)
Bases:
Module3D 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, D, H, W)
- Returns:
output_tensor
- class pymic.net.net3d.scse3d.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.net3d.scse3d.SpatialSELayer3D(num_channels)
Bases:
Module3D Re-implementation of SE block – squeezing spatially and exciting channel-wise described in:
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, D, H, W)
- Returns:
output_tensor
pymic.net.net3d.unet2d5 module
- class pymic.net.net3d.unet2d5.ConvBlockND(in_channels, out_channels, dim=2, dropout_p=0.0)
Bases:
Module2D or 3D convolutional block
- Parameters:
in_channels – (int) Input channel number.
out_channels – (int) Output channel number.
dim – (int) Should be 2 or 3, for 2D and 3D convolution, respectively.
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.net3d.unet2d5.DownBlock(in_channels, out_channels, dim=2, dropout_p=0.0, downsample=True)
Bases:
ModuleConvBlockND block followed by downsampling.
- Parameters:
in_channels – (int) Input channel number.
out_channels – (int) Output channel number.
dim – (int) Should be 2 or 3, for 2D and 3D convolution, respectively.
dropout_p – (int) Dropout probability.
downsample – (bool) Use downsample or not after convolution.
- 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.net3d.unet2d5.UNet2D5(params)
Bases:
ModuleA 2.5D network combining 3D convolutions with 2D convolutions.
Reference: Guotai Wang, Jonathan Shapey, Wenqi Li, Reuben Dorent, Alex Demitriadis, Sotirios Bisdas, Ian Paddick, Robert Bradford, Shaoting Zhang, Sébastien Ourselin, Tom Vercauteren: Automatic Segmentation of Vestibular Schwannoma from T2-Weighted MRI by Deep Spatial Attention with Hardness-Weighted Loss. MICCAI (2) 2019: 264-272.
Note that the attention module in the orininal paper is not used 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 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.
conv_dims – (list) The convolution dimension (2 or 3) 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.net3d.unet2d5.UpBlock(in_channels1, in_channels2, out_channels, dim=2, dropout_p=0.0, bilinear=True)
Bases:
ModuleUpsampling followed by ConvBlockND block
- 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.
dim – (int) Should be 2 or 3, for 2D and 3D convolution, respectively.
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.
pymic.net.net3d.unet3d module
- class pymic.net.net3d.unet3d.ConvBlock(in_channels, out_channels, dropout_p)
Bases:
ModuleTwo 3D 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.net3d.unet3d.Decoder(params)
Bases:
ModuleDecoder of 3D 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.
trilinear – (bool) Using bilinear for up-sampling or not. If False, deconvolution will be used for up-sampling.
multiscale_pred – (bool) Get multi-scale 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.net3d.unet3d.DownBlock(in_channels, out_channels, dropout_p)
Bases:
Module3D 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pymic.net.net3d.unet3d.Encoder(params)
Bases:
ModuleEncoder of 3D 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.net3d.unet3d.UNet3D(params)
Bases:
ModuleAn implementation of the U-Net.
Reference: Özgün Çiçek, Ahmed Abdulkadir, Soeren S. Lienkamp, Thomas Brox, Olaf Ronneberger: 3D U-Net: Learning Dense Volumetric Segmentation from Sparse Annotation. MICCAI (2) 2016: 424-432.
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.
trilinear – (bool) Using trilinear for up-sampling or not. If False, deconvolution will be used for up-sampling.
multiscale_pred – (bool) Get multi-scale 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.net3d.unet3d.UpBlock(in_channels1, in_channels2, out_channels, dropout_p, trilinear=True)
Bases:
Module3D 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.
trilinear – (bool) Use trilinear 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.net3d.unet3d_scse module
- class pymic.net.net3d.unet3d_scse.ConvScSEBlock3D(in_channels, out_channels, dropout_p)
Bases:
ModuleTwo 3D convolutional blocks followed by ChannelSpatialSELayer3D. Each block consists of Conv3d + BatchNorm3d + 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.net3d.unet3d_scse.DownBlock(in_channels, out_channels, dropout_p)
Bases:
Module3D Downsampling followed by ConvScSEBlock3D.
- 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.net3d.unet3d_scse.UNet3D_ScSE(params)
Bases:
ModuleCombining 3D 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.
trilinear – (bool) Using trilinear 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.net3d.unet3d_scse.UpBlock(in_channels1, in_channels2, out_channels, dropout_p, trilinear=True)
Bases:
Module3D Up-sampling followed by ConvScSEBlock3D in UNet3D_ScSE.
- 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.
trilinear – (bool) Use trilinear 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.