models

Standard models for neural networks.

Classes

ModelFeature

Base model feature class.

Convolutional, convolutional

Creates and compiles a convolutional neural network.

UNet, unet

Creates and compiles a U-Net neural network.

RNN, rnn

Creates and compiles a recurrent neural network.

Module classes

Convolutional

class deeptrack.models.Convolutional(input_shape=(51, 51, 1), conv_layers_dimensions=(16, 32, 64, 128), dense_layers_dimensions=(32, 32), number_of_outputs=3, output_activation=None, **kwargs)

Creates and compiles a convolutional neural network.

A convolutional network with a dense top.

Parameters
  • input_shape (tuple of ints) – Size of the images to be analyzed.

  • conv_layers_dimensions (tuple of ints) – Number of convolutions in each convolutional layer.

  • dense_layers_dimensions (tuple of ints) – Number of units in each dense layer.

  • number_of_outputs (int) – Number of units in the output layer.

  • output_activation (str or keras activation) – The activation function of the output.

  • loss (str or keras loss function) – The loss function of the network.

Returns

Deep learning network

Return type

keras.models.Model

ModelFeature

class deeptrack.models.ModelFeature(model: tensorflow.python.keras.engine.training.Model, *, loss='mae', optimizer='adam', metrics=[], add_batch_dimension_on_resolve=True, **kwargs)

Base model feature class.

Extends both feature and keras Model. The class can be treated as either. When resolved, it calls the method predict on the input image.

Parameters
  • model (keras.models.Model) – The keras model to interface.

  • loss (str or keras loss) – The loss function of the model.

  • optimizer (str or keras optimizer) – The optimizer of the model.

  • add_batch_dimension_on_resolve (bool) – Whether to add a dimension before the first axis before calling predict.

call(inputs, **kwargs)

Calls the model on new inputs.

In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).

Parameters
  • inputs – A tensor or list of tensors.

  • training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.

  • mask – A mask or list of masks. A mask can be either a tensor or None (no mask).

Returns

A tensor if there is a single output, or a list of tensors if there are more than one outputs.

get(image, add_batch_dimension_on_resolve, **kwargs)

Method for altering an image Abstract method that define how the feature transforms the input. The current value of all properties will be passed as keyword arguments.

Parameters
  • image (Image or List[Image]) – The Image or list of images to transform

  • **kwargs – The current value of all properties in properties as well as any global arguments.

Returns

The transformed image or list of images

Return type

Image or List[Image]

summary(*args, **kwargs)

Prints a string summary of the network.

Parameters
  • line_length – Total length of printed lines (e.g. set this to adapt the display to different terminal window sizes).

  • positions – Relative or absolute positions of log elements in each line. If not provided, defaults to [.33, .55, .67, 1.].

  • print_fn – Print function to use. Defaults to print. It will be called on each line of the summary. You can set it to a custom function in order to capture the string summary.

Raises

ValueError – if summary() is called before the model is built.

RNN

class deeptrack.models.RNN(input_shape=(51, 51, 1), conv_layers_dimensions=(16, 32, 64, 128), dense_layers_dimensions=(32, ), rnn_layers_dimensions=(32, ), return_sequences=False, output_activation=None, number_of_outputs=3, **kwargs)

Creates and compiles a recurrent neural network.

Parameters
  • input_shape (tuple of ints) – Size of the images to be analyzed.

  • conv_layers_dimensions (tuple of ints) – Number of convolutions in each convolutional layer during down- and upsampling.

  • dense_layers_dimensions (tuple of ints) – Number of units in each dense layer.

  • rnn_layers_dimensions (tuple of ints) – Number of units in each recurrent layer.

  • number_of_outputs (int) – Number of convolutions in output layer.

  • output_activation (str or keras activation) – The activation function of the output.

  • loss (str or keras loss function) – The loss function of the network.

Returns

Deep learning network.

Return type

keras.models.Model

UNet

class deeptrack.models.UNet(input_shape=(None, None, 1), conv_layers_dimensions=(16, 32, 64, 128), base_conv_layers_dimensions=(128, 128), output_conv_layers_dimensions=(16, 16), steps_per_pooling=1, number_of_outputs=1, output_activation=None, loss=<function flatten.<locals>.wrapper>, layer_function=None, **kwargs)

Creates and compiles a U-Net.

Parameters
  • input_shape (tuple of ints) – Size of the images to be analyzed.

  • conv_layers_dimensions (tuple of ints) – Number of convolutions in each convolutional layer during down- and upsampling.

  • base_conv_layers_dimensions (tuple of ints) – Number of convolutions in each convolutional layer at the base of the unet, where the image is the most downsampled.

  • output_conv_layers_dimensions (tuple of ints) – Number of convolutions in each convolutional layer after the upsampling.

  • steps_per_pooling (int) – Number of convolutional layers between each pooling and upsampling step.

  • number_of_outputs (int) – Number of convolutions in output layer.

  • output_activation (str or keras activation) – The activation function of the output.

  • loss (str or keras loss function) – The loss function of the network.

  • layer_function (Callable[int] -> keras layer) – Function that returns a convolutional layer with convolutions determined by the input argument. Can be use to futher customize the network.

Returns

Deep learning network.

Return type

keras.models.Model

convolutional

deeptrack.models.convolutional

alias of deeptrack.models.Convolutional

rnn

deeptrack.models.rnn

alias of deeptrack.models.RNN

unet

deeptrack.models.unet

alias of deeptrack.models.UNet