Keras3DUNet

class radio.models.Keras3DUNet(config=None, *args, **kwargs)[source]

Bases: radio.models.keras.keras_model.KerasModel

Model incapsulating 3D U-Net architecture for 3D scans implemented in keras.

Class extends KerasModel class.

Contains description of ‘bottleneck_block’, ‘reduction_block’ and ‘upsampling_block’. Current 3D U-Net architecture is implemented inside _build method using these blocks.

Architecture is inspired by 3D U-Net (Çiçek et Al., https://arxiv.org/abs/1606.06650).

Notes

Implementation requires the input tensor having shape=(batch_size, 1, 32, 64, 64).

bottleneck_block(inputs, filters, scope, padding='same')[source]

Apply bottleneck block transform to input tensor.

Parameters:
  • inputs (keras tensor) – input tensor.
  • filters (int) – number of output filters required by Conv3D operation.
  • scope (str) – scope name for block, will be used as an argument of tf.variable_scope.
  • padding (str) – padding mode, can be ‘same’ or ‘valid’.
Returns:

output tensor.

Return type:

keras tensor

Notes

channels_first dim-ordering is used.

build_config()[source]
compile(optimizer, loss, metrics=None, loss_weights=None, sample_weight_mode=None, **kwargs)

Configures the model for training.

# Arguments
optimizer: str (name of optimizer) or optimizer object.
See [optimizers](/optimizers).
loss: str (name of objective function) or objective function.
See [losses](/losses). If the model has multiple outputs, you can use a different loss on each output by passing a dictionary or a list of losses. The loss value that will be minimized by the model will then be the sum of all individual losses.
metrics: list of metrics to be evaluated by the model
during training and testing. Typically you will use metrics=[‘accuracy’]. To specify different metrics for different outputs of a multi-output model, you could also pass a dictionary, such as metrics={‘output_a’: ‘accuracy’}.
loss_weights: Optional list or dictionary specifying scalar
coefficients (Python floats) to weight the loss contributions of different model outputs. The loss value that will be minimized by the model will then be the weighted sum of all individual losses, weighted by the loss_weights coefficients. If a list, it is expected to have a 1:1 mapping to the model’s outputs. If a tensor, it is expected to map output names (strings) to scalar coefficients.
sample_weight_mode: if you need to do timestep-wise
sample weighting (2D weights), set this to “temporal”. None defaults to sample-wise weights (1D). If the model has multiple outputs, you can use a different sample_weight_mode on each output by passing a dictionary or a list of modes.
**kwargs: when using the Theano backend, these arguments
are passed into K.function. When using the Tensorflow backend, these arguments are passed into tf.Session.run.
# Raises
ValueError: In case of invalid arguments for
optimizer, loss, metrics or sample_weight_mode.
reduction_block(inputs, filters, scope, pool_size=(2, 2, 2), padding='same')[source]

Apply reduction block transform to input tensor.

Layer consists of two 3D-convolutional layers with batch normalization before ‘relu’ activation and max_pooling3d layer in the end.

Parameters:
  • inputs (keras tensor) – input tensor.
  • filters (int) – number of filters in first and second covnolutions.
  • scope (str) – scope name for block, will be used as an argument of tf.variable_scope.
  • pool_size (tuple(int, int, int)) – size of pooling kernel along three axis, required by Conv3D operation.
  • padding (str) – padding mode for convolutions, can be ‘same’ or ‘valid’.
Returns:

output tensor.

Return type:

keras tensor

Notes

channels_first dim-ordering is used.

upsampling_block(inputs, skip_connect_tensor, filters, scope, padding='same')[source]

Apply upsampling transform to two input tensors.

First of all, UpSampling3D transform is applied to inputs. Then output tensor of operation is concatenated with skip_connect_tensor. After this two 3D-convolutions with batch normalization before ‘relu’ activation are applied.

Parameters:
  • inputs (keras tensor) – input tensor from previous layer.
  • skip_connect_tensor (keras tensor) – input tensor from simmiliar layer from reduction branch of 3D U-Net.
  • filters (int) – number of filters in convolutional layers.
  • scope (str) – name of scope for block.
  • padding (str) – padding mode for convolutions, can be ‘same’ or ‘valid’.
Returns:

ouput tensor.

Return type:

keras tensor

Notes

channels_first dim-ordering is used.