msdnet.network module

Module implementing neural networks.

class msdnet.network.Network[source]

Bases: abc.ABC

Base class for a neural network.

abstract forward(im, returnoutput=True)[source]

Compute a forward pass of the network.

Parameters
  • im – input image (channels x rows x columns)

  • returnoutput – whether to return the output image (default: True)

Returns

output image (channels x rows x columns)

abstract backward(im)[source]

Compute a backpropagation pass of the network. Sensitivity maps of each intermediate image are stored within the network.

Parameters

im – error gradient image (channels x rows x columns)

abstract gradient_zero()[source]

Set all gradient variables to zero.

abstract gradient()[source]

Compute gradient variables using computed sensitivity maps.

abstract getgradients()[source]

Return a flat array with all gradient variables.

Returns

all gradient variables

updategradients(u)[source]

Update variables of network within a thread.

Parameters

u – update variables

abstract updategradients_internal(u)[source]

Update variables of network.

Parameters

u – update variables

abstract to_dict()[source]

Return a dictionary containing all network variables and parameters.

Returns

all network variables and parameters

abstract load_dict(dct)[source]

Set all network variables and parameters from dictionary.

Parameters

dct – all network variables and parameters

abstract classmethod from_dict(dct, gpu=True)[source]

Initialize network and all network variables and parameters from dictionary.

Parameters

dct – all network variables and parameters

classmethod from_file(fn, gpu=True, groupname='network')[source]

Initialize network and all network variables and parameters from file.

Parameters
  • fn – filename

  • gpu – (optional) whether to use GPU or CPU

to_file(fn, groupname='network')[source]

Save all network variables and parameters to file.

Parameters

fn – filename

normalizeinout(datapoints)[source]

Normalize input and output of network to zero mean and unit variance.

Parameters

datapoints – list of datapoints to compute normalization factors with.

class msdnet.network.MSDNet(d, dil, nin, nout, gpu=True)[source]

Bases: msdnet.network.Network

Main implementation of a Mixed-Scale Dense network.

Parameters
  • d – depth of network (width is always 1)

  • dildilations.Dilations class defining dilations

  • nin – number of input channels

  • nout – number of output channels

  • gpu – (optional) whether to use GPU or CPU

forward(im, returnoutput=True)[source]

Compute a forward pass of the network.

Parameters
  • im – input image (channels x rows x columns)

  • returnoutput – whether to return the output image (default: True)

Returns

output image (channels x rows x columns)

backward(im, inputdelta=False)[source]

Compute a backpropagation pass of the network. Sensitivity maps of each intermediate image are stored within the network.

Parameters

im – error gradient image (channels x rows x columns)

initialize()[source]

Initialize network parameters.

gradient_zero()[source]

Set all gradient variables to zero.

gradient()[source]

Compute gradient variables using computed sensitivity maps.

filtergradient()[source]

Compute filter gradient values.

getgradients()[source]

Return a flat array with all gradient variables.

Returns

all gradient variables

updategradients_internal(u)[source]

Update variables of network.

Parameters

u – update variables

setinputscale(gamma, offset)[source]

Set input normalization values.

setoutputscale(gamma, offset)[source]

Set output normalization values.

scaleinput()[source]

Normalize input image.

scaleoutput()[source]

Rescale output image.

scaleoutputback()[source]

Rescale output image during backpropagation.

normalizeinput(datapoints)[source]

Normalize input of network to zero mean and unit variance.

Parameters

datapoints – list of datapoints to compute normalization factors with.

normalizeoutput(datapoints)[source]

Normalize output of network to zero mean and unit variance.

Parameters

datapoints – list of datapoints to compute normalization factors with.

to_dict()[source]

Return a dictionary containing all network variables and parameters.

Returns

all network variables and parameters

load_dict(dct)[source]

Set all network variables and parameters from dictionary.

Parameters

dct – all network variables and parameters

classmethod from_dict(dct, gpu=True)[source]

Initialize network and all network variables and parameters from dictionary.

Parameters

dct – all network variables and parameters

class msdnet.network.SegmentationMSDNet(*args, **kwargs)[source]

Bases: msdnet.network.MSDNet

Main implementation of a Mixed-Scale Dense network for segmentation.

Same parameters as MSDNet.

forward(im, returnoutput=True)[source]

Compute a forward pass of the network.

Parameters
  • im – input image (channels x rows x columns)

  • returnoutput – whether to return the output image (default: True)

Returns

output image (channels x rows x columns)

normalizeoutput(datapoints)[source]

Normalize output of network to zero mean and unit variance.

Parameters

datapoints – list of datapoints to compute normalization factors with.