dltk.networks.segmentation package

dltk.networks.segmentation.deepmedic module

dltk.networks.segmentation.deepmedic.crop_central_block(x, size)[source]
dltk.networks.segmentation.deepmedic.deepmedic_3d(inputs, num_classes, normal_filters=(30, 30, 40, 40, 40, 40, 50, 50), normal_strides=((1, 1, 1), (1, 1, 1), (1, 1, 1), (1, 1, 1), (1, 1, 1), (1, 1, 1), (1, 1, 1), (1, 1, 1)), normal_kernels=((3, 3, 3), (3, 3, 3), (3, 3, 3), (3, 3, 3), (3, 3, 3), (3, 3, 3), (3, 3, 3), (3, 3, 3)), normal_residuals=(4, 6, 8), normal_input_shape=(25, 25, 25), subsampled_filters=((30, 30, 40, 40, 40, 40, 50, 50), ), subsampled_strides=(((1, 1, 1), (1, 1, 1), (1, 1, 1), (1, 1, 1), (1, 1, 1), (1, 1, 1), (1, 1, 1), (1, 1, 1)), ), subsampled_kernels=(((3, 3, 3), (3, 3, 3), (3, 3, 3), (3, 3, 3), (3, 3, 3), (3, 3, 3), (3, 3, 3), (3, 3, 3)), ), subsampled_residuals=((4, 6, 8), ), subsampled_input_shapes=((57, 57, 57), ), subsample_factors=((3, 3, 3), ), fc_filters=(150, 150), first_fc_kernel=(3, 3, 3), fc_residuals=(2, ), padding=u'VALID', use_prelu=True, mode='eval', use_bias=True, kernel_initializer=<tensorflow.python.ops.init_ops.VarianceScaling object>, bias_initializer=<tensorflow.python.ops.init_ops.Zeros object>, kernel_regularizer=None, bias_regularizer=None)[source]

Image segmentation network based on a DeepMedic architecture [1, 2]. Downsampling of features is done via strided convolutions. The architecture uses multiple processing paths with different resolutions. The different pathways are concatenated and then fed to the convolutional fc layers.

[1] Konstantinos Kamnitsas et al. Efficient Multi-Scale 3D CNN with Fully
Connected CRF for Accurate Brain Lesion Segmentation. Medical Image Analysis, 2016.
[2] Konstantinos Kamnitsas et al. Multi-Scale 3D CNNs for segmentation of
brain Lesions in multi-modal MRI. ISLES challenge, MICCAI 2015.

Note: We are currently using bilinear upsampling whereas the original implementation (https://github.com/Kamnitsask/deepmedic) uses repeat upsampling.

Parameters:
  • inputs (tf.Tensor) – Input feature tensor to the network (rank 5 required).
  • num_classes (int) – Number of output classes.
  • normal_filters (array_like, optional) – Number of filters for each layer for normal path.
  • normal_strides (array_like, optional) – Strides for each layer for normal path.
  • normal_kernels (array_like, optional) – Kernel size for each layer for normal path.
  • normal_residuals (array_like, optional) – Location of residual connections for normal path.
  • normal_input_shape (array_like, optional) – Shape of input to normal path. Input to the network is center cropped to this shape.
  • subsampled_filters (array_like, optional) – Number of filters for each layer for each subsampled path.
  • subsampled_strides (array_like, optional) – Strides for each layer for each subsampled path.
  • subsampled_kernels (array_like, optional) – Kernel size for each layer for each subsampled path.
  • subsampled_residuals (array_like, optional) – Location of residual connections for each subsampled path.
  • subsampled_input_shapes (array_like, optional) – Shape of input to subsampled paths. Input to the network is downsampled and then center cropped to this shape.
  • subsample_factors (array_like, optional) – Downsampling factors for each subsampled path.
  • fc_filters (array_like, optional) – Number of filters for the fc layers.
  • first_fc_kernel (array_like, optional) – Shape of the kernel of the first fc layer.
  • fc_residuals (array_like, optional) – Location of residual connections for the fc layers.
  • padding (string, optional) – Type of padding used for convolutions. Standard is VALID
  • use_prelu (bool, optional) – Flag to enable PReLU activation. Alternatively leaky ReLU is used. Defaults to True.
  • mode (TYPE, optional) – One of the tf.estimator.ModeKeys strings: TRAIN, EVAL or PREDICT
  • use_bias (bool, optional) – Boolean, whether the layer uses a bias.
  • kernel_initializer (TYPE, optional) – An initializer for the convolution kernel.
  • bias_initializer (TYPE, optional) – An initializer for the bias vector. If None, no bias will be applied.
  • kernel_regularizer (None, optional) – Optional regularizer for the convolution kernel.
  • bias_regularizer (None, optional) – Optional regularizer for the bias vector.
Returns:

dictionary of output tensors

Return type:

dict

dltk.networks.segmentation.fcn module

dltk.networks.segmentation.fcn.residual_fcn_3d(inputs, num_classes, num_res_units=1, filters=(16, 32, 64, 128), strides=((1, 1, 1), (2, 2, 2), (2, 2, 2), (2, 2, 2)), mode='eval', use_bias=False, activation=<function relu6>, kernel_initializer=<tensorflow.python.ops.init_ops.VarianceScaling object>, bias_initializer=<tensorflow.python.ops.init_ops.Zeros object>, kernel_regularizer=None, bias_regularizer=None)[source]

Image segmentation network based on an FCN architecture [1] using residual units [2] as feature extractors. Downsampling and upsampling of features is done via strided convolutions and transpose convolutions, respectively. On each resolution scale s are num_residual_units with filter size = filters[s]. strides[s] determine the downsampling factor at each resolution scale.

[1] J. Long et al. Fully convolutional networks for semantic segmentation.
CVPR 2015.

[2] K. He et al. Identity Mappings in Deep Residual Networks. ECCV 2016.

Parameters:
  • inputs (tf.Tensor) – Input feature tensor to the network (rank 5 required).
  • num_classes (int) – Number of output classes.
  • num_res_units (int, optional) – Number of residual units at each resolution scale.
  • filters (tuple, optional) – Number of filters for all residual units at each resolution scale.
  • strides (tuple, optional) – Stride of the first unit on a resolution scale.
  • mode (TYPE, optional) – One of the tf.estimator.ModeKeys strings: TRAIN, EVAL or PREDICT
  • use_bias (bool, optional) – Boolean, whether the layer uses a bias.
  • activation (optional) – A function to use as activation function.
  • kernel_initializer (TYPE, optional) – An initializer for the convolution kernel.
  • bias_initializer (TYPE, optional) – An initializer for the bias vector. If None, no bias will be applied.
  • kernel_regularizer (None, optional) – Optional regularizer for the convolution kernel.
  • bias_regularizer (None, optional) – Optional regularizer for the bias vector.
Returns:

dictionary of output tensors

Return type:

dict

dltk.networks.segmentation.fcn.upscore_layer_3d(inputs, inputs2, out_filters, in_filters=None, strides=(2, 2, 2), mode='eval', use_bias=False, kernel_initializer=<tensorflow.python.ops.init_ops.VarianceScaling object>, bias_initializer=<tensorflow.python.ops.init_ops.Zeros object>, kernel_regularizer=None, bias_regularizer=None)[source]

Upscore layer according to [1].

[1] J. Long et al. Fully convolutional networks for semantic segmentation. CVPR 2015.

Parameters:
  • inputs (tf.Tensor) – Input features to be upscored.
  • inputs2 (tf.Tensor) – Higher resolution features from the encoder to add. out_filters (int): Number of output filters (typically, number of segmentation classes)
  • in_filters (None, optional) – None or number of input filters.
  • strides (tuple, optional) – Upsampling factor for a strided transpose convolution.
  • mode (TYPE, optional) – One of the tf.estimator.ModeKeys strings: TRAIN, EVAL or PREDICT
  • use_bias (bool, optional) – Boolean, whether the layer uses a bias.
  • kernel_initializer (TYPE, optional) – An initializer for the convolution kernel.
  • bias_initializer (TYPE, optional) – An initializer for the bias vector. If None, no bias will be applied.
  • kernel_regularizer (None, optional) – Optional regularizer for the convolution kernel.
  • bias_regularizer (None, optional) – Optional regularizer for the bias vector.
Returns:

Upscore tensor

Return type:

tf.Tensor

dltk.networks.segmentation.unet module

dltk.networks.segmentation.unet.asymmetric_residual_unet_3d(inputs, num_classes, num_res_units=1, filters=(16, 32, 64, 128), strides=((1, 1, 1), (2, 2, 2), (2, 2, 2), (2, 2, 2)), mode='eval', use_bias=False, activation=<function leaky_relu>, kernel_initializer=<tensorflow.python.ops.init_ops.VarianceScaling object>, bias_initializer=<tensorflow.python.ops.init_ops.Zeros object>, kernel_regularizer=None, bias_regularizer=None)[source]

Image segmentation network based on a flexible UNET architecture [1] using residual units [2] as feature extractors. Downsampling and upsampling of features is done via strided convolutions and transpose convolutions, respectively. On each resolution scale s are num_residual_units with filter size = filters[s]. strides[s] determine the downsampling factor at each resolution scale.

[1] O. Ronneberger et al. U-Net: Convolutional Networks for Biomedical Image
Segmentation. MICCAI 2015.

[2] K. He et al. Identity Mappings in Deep Residual Networks. ECCV 2016.

Parameters:
  • inputs (tf.Tensor) – Input feature tensor to the network (rank 5 required).
  • num_classes (int) – Number of output classes.
  • num_res_units (int, optional) – Number of residual units at each resolution scale.
  • filters (tuple, optional) – Number of filters for all residual units at each resolution scale.
  • strides (tuple, optional) – Stride of the first unit on a resolution scale.
  • mode (TYPE, optional) – One of the tf.estimator.ModeKeys strings: TRAIN, EVAL or PREDICT
  • use_bias (bool, optional) – Boolean, whether the layer uses a bias.
  • activation (optional) – A function to use as activation function.
  • kernel_initializer (TYPE, optional) – An initializer for the convolution kernel.
  • bias_initializer (TYPE, optional) – An initializer for the bias vector. If None, no bias will be applied.
  • kernel_regularizer (None, optional) – Optional regularizer for the convolution kernel.
  • bias_regularizer (None, optional) – Optional regularizer for the bias vector.
Returns:

dictionary of output tensors

Return type:

dict

dltk.networks.segmentation.unet.residual_unet_3d(inputs, num_classes, num_res_units=1, filters=(16, 32, 64, 128), strides=((1, 1, 1), (2, 2, 2), (2, 2, 2), (2, 2, 2)), mode='eval', use_bias=False, activation=<function leaky_relu>, kernel_initializer=<tensorflow.python.ops.init_ops.VarianceScaling object>, bias_initializer=<tensorflow.python.ops.init_ops.Zeros object>, kernel_regularizer=None, bias_regularizer=None)[source]

Image segmentation network based on a flexible UNET architecture [1] using residual units [2] as feature extractors. Downsampling and upsampling of features is done via strided convolutions and transpose convolutions, respectively. On each resolution scale s are num_residual_units with filter size = filters[s]. strides[s] determine the downsampling factor at each resolution scale.

[1] O. Ronneberger et al. U-Net: Convolutional Networks for Biomedical Image
Segmentation. MICCAI 2015.

[2] K. He et al. Identity Mappings in Deep Residual Networks. ECCV 2016.

Parameters:
  • inputs (tf.Tensor) – Input feature tensor to the network (rank 5 required).
  • num_classes (int) – Number of output classes.
  • num_res_units (int, optional) – Number of residual units at each resolution scale.
  • filters (tuple, optional) – Number of filters for all residual units at each resolution scale.
  • strides (tuple, optional) – Stride of the first unit on a resolution scale.
  • mode (TYPE, optional) – One of the tf.estimator.ModeKeys strings: TRAIN, EVAL or PREDICT
  • use_bias (bool, optional) – Boolean, whether the layer uses a bias.
  • activation (optional) – A function to use as activation function.
  • kernel_initializer (TYPE, optional) – An initializer for the convolution kernel.
  • bias_initializer (TYPE, optional) – An initializer for the bias vector. If None, no bias will be applied.
  • kernel_regularizer (None, optional) – Optional regularizer for the convolution kernel.
  • bias_regularizer (None, optional) – Optional regularizer for the bias vector.
Returns:

dictionary of output tensors

Return type:

dict

dltk.networks.segmentation.unet.upsample_and_concat(inputs, inputs2, strides=(2, 2, 2))[source]

Upsampling and concatenation layer according to [1].

[1] O. Ronneberger et al. U-Net: Convolutional Networks for Biomedical Image
Segmentation. MICCAI 2015.
Parameters:
  • inputs (TYPE) – Input features to be upsampled.
  • inputs2 (TYPE) – Higher resolution features from the encoder to concatenate.
  • strides (tuple, optional) – Upsampling factor for a strided transpose convolution.
Returns:

Upsampled feature tensor

Return type:

tf.Tensor

Module contents