Model (Tensorflow Backend)

MDGRUClassification

class mdgru.model.mdgru_classification.MDGRUClassification(data, target, dropout, kw)[source]

Bases: mdgru.model.ClassificationModel, mdgru.model.mdrnn.MDGRUNet

Provides a full MDGRU default network.

Using this class, Using the parameters fc_channels and mdgru_channels, which have to be lists of the same length, a MDGRU network of a number of mdgru and voxel-wise fully connected layers can be generated. Strides can be set for each MDGRU layer as a list of lists of strides per dimension. Furthermore, entries in fc_channels may be None, when MDGRU layer should be stacked directly after each other.

Parameters:
  • ignore_label – Implements omitting a certain label, usage of this parameter is discouraged.
  • fc_channels – Defines the number of channels per voxel-wise fully connected layer
  • mdgru_channels – Defines the number of channels per MDGRU layer
  • strides – list of list defining the strides per dimension per MDGRU layer. None means strides of 1
_defaults = {'model_seed': {'value': 12345678, 'help': 'Override default model initialization random seed'}}
static collect_parameters()[source]
static compile_arguments(kw, keep_entries=True)[source]
cost

lazy property to compute the cost per batch

costs

Cross entropy cost function

get_model_name_from_ckpt(ckpt)

returns root node name of tensorflow graph stored in checkpoint ckpt

logits

Provides the logits of the prediction

mdgru_bb(inp, dropout, num_hidden, num_output, noactivation=False, name=None, **kw)

Convenience function to combine a MDRNN layer with a voxel-wise fully connected layer.

Parameters:
  • inp – input data
  • dropout – dropout rate
  • num_hidden – number of hidden units, output units of the MDRNN
  • num_output – number of output units of the voxel-wise fully connected layer (Can be None -> no voxel-wise fully connected layer)
  • noactivation – Flag to disable activation of voxel-wise fully connected layer
  • name – Name for this particular MDRNN + vw fully connected layer
  • kw – Arguments for MDRNN and the vw fully connected layer (can override this class’ attributes)
Returns:

Output of the voxelwise fully connected layer and MDRNN mix

optimize

Optimization routine using the Adadelta optimizer

prediction

Provides prediction in the form of a discrete probability distribution per voxel

set_allowed_gpu_memory_fraction(gpuboundfraction)
class mdgru.model.mdgru_classification.MDGRUClassificationWithDiceLoss(data, target, dropout, kw)[source]

Bases: mdgru.model.mdgru_classification.MDGRUClassification

_defaults = {'model_seed': {'value': 12345678, 'help': 'Override default model initialization random seed'}}
collect_parameters()
compile_arguments(kw, keep_entries=True)
cost

lazy property to compute the cost per batch

costs
get_model_name_from_ckpt(ckpt)

returns root node name of tensorflow graph stored in checkpoint ckpt

logits

Provides the logits of the prediction

mdgru_bb(inp, dropout, num_hidden, num_output, noactivation=False, name=None, **kw)

Convenience function to combine a MDRNN layer with a voxel-wise fully connected layer.

Parameters:
  • inp – input data
  • dropout – dropout rate
  • num_hidden – number of hidden units, output units of the MDRNN
  • num_output – number of output units of the voxel-wise fully connected layer (Can be None -> no voxel-wise fully connected layer)
  • noactivation – Flag to disable activation of voxel-wise fully connected layer
  • name – Name for this particular MDRNN + vw fully connected layer
  • kw – Arguments for MDRNN and the vw fully connected layer (can override this class’ attributes)
Returns:

Output of the voxelwise fully connected layer and MDRNN mix

optimize

Optimization routine using the Adadelta optimizer

prediction

Provides prediction in the form of a discrete probability distribution per voxel

set_allowed_gpu_memory_fraction(gpuboundfraction)
class mdgru.model.mdgru_classification.MDGRUClassificationWithGeneralizedDiceLoss(data, target, dropout, kw)[source]

Bases: mdgru.model.mdgru_classification.MDGRUClassification

_defaults = {'model_seed': {'value': 12345678, 'help': 'Override default model initialization random seed'}}
collect_parameters()
compile_arguments(kw, keep_entries=True)
cost

lazy property to compute the cost per batch

costs
get_model_name_from_ckpt(ckpt)

returns root node name of tensorflow graph stored in checkpoint ckpt

logits

Provides the logits of the prediction

mdgru_bb(inp, dropout, num_hidden, num_output, noactivation=False, name=None, **kw)

Convenience function to combine a MDRNN layer with a voxel-wise fully connected layer.

Parameters:
  • inp – input data
  • dropout – dropout rate
  • num_hidden – number of hidden units, output units of the MDRNN
  • num_output – number of output units of the voxel-wise fully connected layer (Can be None -> no voxel-wise fully connected layer)
  • noactivation – Flag to disable activation of voxel-wise fully connected layer
  • name – Name for this particular MDRNN + vw fully connected layer
  • kw – Arguments for MDRNN and the vw fully connected layer (can override this class’ attributes)
Returns:

Output of the voxelwise fully connected layer and MDRNN mix

optimize

Optimization routine using the Adadelta optimizer

prediction

Provides prediction in the form of a discrete probability distribution per voxel

set_allowed_gpu_memory_fraction(gpuboundfraction)

Module Contents

class mdgru.model.ClassificationModel(data, target, dropout, kw)[source]

Bases: mdgru.model.Model

Abstract model class.

_defaults = {'model_seed': {'value': 12345678, 'help': 'Override default model initialization random seed'}}
cost

lazy property to compute the cost per batch

costs()

lazy property to compute the costs per sample.

get_model_name_from_ckpt(ckpt)

returns root node name of tensorflow graph stored in checkpoint ckpt

prediction()

lazy property call to produce a prediction in tensorflow.

set_allowed_gpu_memory_fraction(gpuboundfraction)
class mdgru.model.GANModel(data, dropout, kw)[source]

Bases: mdgru.model.Model

Abstract model class for GANs.

_defaults = {'model_seed': {'value': 12345678, 'help': 'Override default model initialization random seed'}}
cost

lazy property to compute the cost per batch

costs()

lazy property to compute the costs per sample.

get_model_name_from_ckpt(ckpt)

returns root node name of tensorflow graph stored in checkpoint ckpt

prediction()

lazy property call to produce a prediction in tensorflow.

set_allowed_gpu_memory_fraction(gpuboundfraction)
class mdgru.model.Model(data, target, dropout, kw)[source]

Bases: object

Abstract Model class

Parameters:kw (dict containing the following options.) –
  • model_seed [default: 12345678] Override default model initialization random seed
_defaults = {'model_seed': {'value': 12345678, 'help': 'Override default model initialization random seed'}}
cost

lazy property to compute the cost per batch

costs()[source]

lazy property to compute the costs per sample.

static get_model_name_from_ckpt(ckpt)[source]

returns root node name of tensorflow graph stored in checkpoint ckpt

prediction()[source]

lazy property call to produce a prediction in tensorflow.

static set_allowed_gpu_memory_fraction(gpuboundfraction)[source]
class mdgru.model.ReconstructionModel(data, dropout, kw)[source]

Bases: mdgru.model.Model

Abstract model class for reconstruction tasks.

_defaults = {'model_seed': {'value': 12345678, 'help': 'Override default model initialization random seed'}}
cost

lazy property to compute the cost per batch

costs()

lazy property to compute the costs per sample.

get_model_name_from_ckpt(ckpt)

returns root node name of tensorflow graph stored in checkpoint ckpt

prediction()

lazy property call to produce a prediction in tensorflow.

set_allowed_gpu_memory_fraction(gpuboundfraction)
class mdgru.model.RegressionModel(data, target, dropout, kw)[source]

Bases: mdgru.model.Model

Abstract model class for regression tasks.

_defaults = {'model_seed': {'value': 12345678, 'help': 'Override default model initialization random seed'}}
cost

lazy property to compute the cost per batch

costs()

lazy property to compute the costs per sample.

get_model_name_from_ckpt(ckpt)

returns root node name of tensorflow graph stored in checkpoint ckpt

prediction()

lazy property call to produce a prediction in tensorflow.

set_allowed_gpu_memory_fraction(gpuboundfraction)
mdgru.model._save_summary_for_2d_image(name, grid, num_channels, collections=[])[source]

Helper to summarize 2d images in tensorboard, by saving one for each channel. :param name: name of the image to be saved :param grid: 2d image :param num_channels: num channels to display :param collections: which collection should be used for tensorboard, defaults to default summary collection.

mdgru.model.batch_norm(x, name_scope, training, epsilon=0.001, decay=0.999, bias=True, m=None)[source]

Computes the batch_norm for x

mdgru.model.convolution_helper_padding_same(inp, convolution_filter, filter_shape, strides)[source]

Helper to allow for convolution strides with less than 1.

Strides less than one are performed using transposed convolutions, strides larger than one are performed using normal convolutions. This helper function only works if all filters are larger or equal than one or smaller or equal than 1. If this is not given, an error is raised. given that the used padding is chosen to be “SAME”. :param inp: input data to convolve :param convolution_filter: filter to perform convolution with :param filter_shape: filter shape as list :param strides: list of strides to be used for the spatial dimensions of inp during the convolution. :return:

mdgru.model.get_modified_xavier_method(num_elements, uniform_init=False)[source]

Modified Glorot initializer.

Returns an initializer using Glorots method for uniform or Gaussian distributions depending on the flag “uniform_init”. :param num_elements: How many elements are there :param uniform_init: Shall we use uniform or Gaussian distribution? :return: Glorot/Xavier initializer

mdgru.model.get_pseudo_orthogonal_block_circulant_initialization()[source]

Creates pseudo-orthogonal initialization for given shape.

Pseudo-orthogonal initialization is achieved assuming circular convolution and a signal size equal to the filter size. Hence, if applied to signals larger than the filter, or not using circular convolution leads to non orthogonal filter initializations.

Returns:pseudo-orthogonal initialization for given shape
mdgru.model.save_summary_for_nd_images(name, grid, collections=[])[source]

Helper to summarize 3d images in tensorboard, saving an image along each axis. :param name: name of image :param grid: image data :param collections: collection this image is associated with, defaults to the standard tensorboard summary collection