mt.tf.keras_layers

Submodules

Functions

  • conv2d(): Wrapper of Keras Conv2D layer with a LayerNormalization layer.

  • dense2d(): Wrapper of Keras Conv2D layer with a LayerNormalization layer.

mt.tf.keras_layers.conv2d(name_scope: NameScope, x, filters, kernel_size, **kwargs)

Wrapper of Keras Conv2D layer with a LayerNormalization layer.

Parameters:
  • name_scope (mt.tf.NameScope) – the name scope. For every conv2d invocation, the name scope is iterated.

  • x (tensor-like) – Keras tensor or TF tensor as input

  • filters (int) – The dimensionality of the output space (i.e. the number of output filters in the convolution).

  • kernel_size (int or tuple or list) – An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.

  • **kwargs (dict) – all other keyword arguments to be passed as-is to Conv2D layer construction

Returns:

TF tensor as output

Return type:

tensor-like

mt.tf.keras_layers.dense2d(name_scope: NameScope, x, filters, kernel_size, activation='tanh', **kwargs)

Wrapper of Keras Conv2D layer with a LayerNormalization layer.

TBD. But basically, prenorm, then expand to twice the dim, then prenorm, then project to target dim with target kernel size

Parameters:
  • name_scope (mt.tf.NameScope) – the name scope. For every conv2d invocation, the name scope is iterated.

  • x (tensor-like) – Keras tensor or TF tensor as input

  • filters (int) – The dimensionality of the output space (i.e. the number of output filters in the convolution).

  • kernel_size (int or tuple or list) – An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.

  • activation (object) – the activation of the last conv layer

  • **kwargs (dict) – all other keyword arguments to be passed as-is to Conv2D layer construction

Returns:

TF tensor as output

Return type:

tensor-like

Classes

  • Identical: An identical layer, mainly for renaming purposes.

  • Floor: TensorFlow floor but gradient is identity.

  • VarianceRegularizer: A regularizer on the variance of the input tensor.

  • SimpleMHA2D: SimpleMHA2D layer.

  • MHAPool2D: Pooling in 2D using Keras-based self-attention.

  • DUCLayer: Base layer for all DUC layer implementations.

  • Downsize2D: Downsizing along the x-axis and the y-axis using convolutions of residuals.

  • Upsize2D: Upsizing along the x-axis and the y-axis using convolutions of residuals.

  • Downsize2D_V2: Downsizing along the x-axis and the y-axis using convolutions of residuals.

  • Upsize2D_V2: Upsizing along the x-axis and the y-axis using convolutions of residuals.

  • Downsize2D_V3: Downsizing along the x-axis and the y-axis using convolutions of residuals.

  • Downsize2D_V4: Downsizing along the x-axis and the y-axis using convolutions of residuals.

  • DownsizeX2D: Downsizing along the x-axis and the y-axis using convolutions of residuals.

  • UpsizeX2D: Downsizing along the x-axis and the y-axis using convolutions of residuals.

  • DownsizeY2D: Downsizing along the x-axis and the y-axis using convolutions of residuals.

  • UpsizeY2D: Downsizing along the x-axis and the y-axis using convolutions of residuals.

  • Counter: A layer that counts from 0 during training and does nothing during inference.

class mt.tf.keras_layers.Identical(*args, **kwargs)

An identical layer, mainly for renaming purposes.

Inheritance

digraph inheritance645e59be87 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoTrackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Manages dependencies on other objects."]; "Trackable" -> "AutoTrackable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Identical" [URL="#mt.tf.keras_layers.Identical",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="An identical layer, mainly for renaming purposes."]; "Layer" -> "Identical" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Layer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This is the class from which all layers inherit."]; "Module" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Chooses between Keras v1 and v2 Layer class."]; "Module" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base neural network module class."]; "AutoTrackable" -> "Module" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Trackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for `Trackable` objects without automatic dependencies."]; }
call(x)

This is where the layer’s logic lives.

The call() method may not create state (except in its first invocation, wrapping the creation of variables or other resources in tf.init_scope()). It is recommended to create state in __init__(), or the build() method that is called automatically before call() executes the first time.

Parameters:
  • inputs

    Input tensor, or dict/list/tuple of input tensors. The first positional inputs argument is subject to special rules: - inputs must be explicitly passed. A layer cannot have zero

    arguments, and inputs cannot be provided via the default value of a keyword argument.

    • NumPy array or Python scalar values in inputs get cast as tensors.

    • Keras mask metadata is only collected from inputs.

    • Layers are built (build(input_shape) method) using shape info from inputs only.

    • input_spec compatibility is only checked against inputs.

    • Mixed precision input casting is only applied to inputs. If a layer has tensor arguments in *args or **kwargs, their casting behavior in mixed precision should be handled manually.

    • The SavedModel input specification is generated using inputs only.

    • Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for inputs and not for tensors in positional and keyword arguments.

  • *args – Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above.

  • **kwargs

    Additional keyword arguments. May contain tensors, although this is not recommended, for the reasons above. The following optional keyword arguments are reserved: - training: Boolean scalar tensor of Python boolean indicating

    whether the call is meant for training or inference.

    • mask: Boolean input mask. If the layer’s call() method takes a mask argument, its default value will be set to the mask generated for inputs by the previous layer (if input did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).

Returns:

A tensor or list/tuple of tensors.

compute_output_shape(input_shape)

Computes the output shape of the layer.

This method will cause the layer’s state to be built, if that has not happened before. This requires that the layer will later be used with inputs that match the input shape provided here.

Parameters:

input_shape – Shape tuple (tuple of integers) or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns:

An input shape tuple.

class mt.tf.keras_layers.Floor(*args, **kwargs)

TensorFlow floor but gradient is identity.

Inheritance

digraph inheritance9f3fd5cfa8 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoTrackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Manages dependencies on other objects."]; "Trackable" -> "AutoTrackable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Floor" [URL="#mt.tf.keras_layers.Floor",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="TensorFlow floor but gradient is identity."]; "Layer" -> "Floor" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Layer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This is the class from which all layers inherit."]; "Module" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Chooses between Keras v1 and v2 Layer class."]; "Module" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base neural network module class."]; "AutoTrackable" -> "Module" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Trackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for `Trackable` objects without automatic dependencies."]; }
call(x)

This is where the layer’s logic lives.

The call() method may not create state (except in its first invocation, wrapping the creation of variables or other resources in tf.init_scope()). It is recommended to create state in __init__(), or the build() method that is called automatically before call() executes the first time.

Parameters:
  • inputs

    Input tensor, or dict/list/tuple of input tensors. The first positional inputs argument is subject to special rules: - inputs must be explicitly passed. A layer cannot have zero

    arguments, and inputs cannot be provided via the default value of a keyword argument.

    • NumPy array or Python scalar values in inputs get cast as tensors.

    • Keras mask metadata is only collected from inputs.

    • Layers are built (build(input_shape) method) using shape info from inputs only.

    • input_spec compatibility is only checked against inputs.

    • Mixed precision input casting is only applied to inputs. If a layer has tensor arguments in *args or **kwargs, their casting behavior in mixed precision should be handled manually.

    • The SavedModel input specification is generated using inputs only.

    • Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for inputs and not for tensors in positional and keyword arguments.

  • *args – Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above.

  • **kwargs

    Additional keyword arguments. May contain tensors, although this is not recommended, for the reasons above. The following optional keyword arguments are reserved: - training: Boolean scalar tensor of Python boolean indicating

    whether the call is meant for training or inference.

    • mask: Boolean input mask. If the layer’s call() method takes a mask argument, its default value will be set to the mask generated for inputs by the previous layer (if input did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).

Returns:

A tensor or list/tuple of tensors.

compute_output_shape(input_shape)

Computes the output shape of the layer.

This method will cause the layer’s state to be built, if that has not happened before. This requires that the layer will later be used with inputs that match the input shape provided here.

Parameters:

input_shape – Shape tuple (tuple of integers) or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns:

An input shape tuple.

class mt.tf.keras_layers.VarianceRegularizer(*args, **kwargs)

A regularizer on the variance of the input tensor.

Negative rate for making the variance larger. Positive rate for making the variance smaller.

Inheritance

digraph inheritance4515c277e5 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoTrackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Manages dependencies on other objects."]; "Trackable" -> "AutoTrackable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Layer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This is the class from which all layers inherit."]; "Module" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Chooses between Keras v1 and v2 Layer class."]; "Module" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base neural network module class."]; "AutoTrackable" -> "Module" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Trackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for `Trackable` objects without automatic dependencies."]; "VarianceRegularizer" [URL="#mt.tf.keras_layers.VarianceRegularizer",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A regularizer on the variance of the input tensor."]; "Layer" -> "VarianceRegularizer" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
call(x)

This is where the layer’s logic lives.

The call() method may not create state (except in its first invocation, wrapping the creation of variables or other resources in tf.init_scope()). It is recommended to create state in __init__(), or the build() method that is called automatically before call() executes the first time.

Parameters:
  • inputs

    Input tensor, or dict/list/tuple of input tensors. The first positional inputs argument is subject to special rules: - inputs must be explicitly passed. A layer cannot have zero

    arguments, and inputs cannot be provided via the default value of a keyword argument.

    • NumPy array or Python scalar values in inputs get cast as tensors.

    • Keras mask metadata is only collected from inputs.

    • Layers are built (build(input_shape) method) using shape info from inputs only.

    • input_spec compatibility is only checked against inputs.

    • Mixed precision input casting is only applied to inputs. If a layer has tensor arguments in *args or **kwargs, their casting behavior in mixed precision should be handled manually.

    • The SavedModel input specification is generated using inputs only.

    • Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for inputs and not for tensors in positional and keyword arguments.

  • *args – Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above.

  • **kwargs

    Additional keyword arguments. May contain tensors, although this is not recommended, for the reasons above. The following optional keyword arguments are reserved: - training: Boolean scalar tensor of Python boolean indicating

    whether the call is meant for training or inference.

    • mask: Boolean input mask. If the layer’s call() method takes a mask argument, its default value will be set to the mask generated for inputs by the previous layer (if input did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).

Returns:

A tensor or list/tuple of tensors.

get_config()

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

class mt.tf.keras_layers.SimpleMHA2D(*args, **kwargs)

SimpleMHA2D layer.

This is a simplified version of the Keras-based MultiHeadAttention layer.

The layer takes as input a high-dim image tensor of shape [B, H, W, KV] where B is the batch size, H and W are the grid resolution, and KV is the (high) number of channels. It then 2D-convolves the tensor into 2 tensors, key of shape [B, H, W, N*K] and value of shape [B, H, W, N*V] where N is the number of heads, K is the key dimensionality and V is the value dimensionality. In the absence of V, V is set to K. Next, it reshapes key as [B, H*W, N, K] and value as [B, H*W, N, V]. key is then dot-producted with an internal query tensor of shape [1, 1, N, K] with broadcasting, forming a tensor of shape [B, H*W, N]. This tensor is softmaxed along the axis containing H*W and reshaped as [B, H*W, N, 1], and then multiplied with value and sum-reduced along the axis containing H*W, forming an output attention tensor of shape [B, N, V].

Parameters:
  • num_heads (int) – Number of attention heads.

  • key_dim (int) – Size of each attention head for query and key.

  • value_dim (int, optional) – Size of each attention head for value.

  • use_bias (bool) – Whether the convolutional layers use bias vectors/matrices.

  • activation (object) – activation for the value convolution

  • kernel_initializer (object) – Initializer for convolutional layer kernels.

  • bias_initializer (object) – Initializer for convolutional layer biases.

  • kernel_regularizer (object) – Regularizer for convolutional layer kernels.

  • bias_regularizer (object) – Regularizer for convolutional layer biases.

  • kernel_constraint (object) – Contraint function applied to the layer kernels.

  • bias_constraint (object) – Contraint function applied to the layer biases.

  • dropout (float) – dropout probability

Examples

>>> layer = SimpleMHA2D(num_heads=3, key_dim=40, value_dim=80)
>>> input_tensor = tf.keras.Input(shape=[8, 8, 160])
>>> output_tensor = layer(input_tensor)
>>> print(output_tensor.shape)
(None, 3, 80)

Inheritance

digraph inheritance275ffec317 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoTrackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Manages dependencies on other objects."]; "Trackable" -> "AutoTrackable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Layer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This is the class from which all layers inherit."]; "Module" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Chooses between Keras v1 and v2 Layer class."]; "Module" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base neural network module class."]; "AutoTrackable" -> "Module" [arrowsize=0.5,style="setlinewidth(0.5)"]; "SimpleMHA2D" [URL="#mt.tf.keras_layers.SimpleMHA2D",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="SimpleMHA2D layer."]; "Layer" -> "SimpleMHA2D" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Trackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for `Trackable` objects without automatic dependencies."]; }
call(key_value, training=None)

The call function.

Parameters:
  • key_value (tensorflow.Tensor) – input Tensor of shape (B, H, W, KV).

  • training (bool) – Whether the layer should behave in training mode or in inference mode.

Returns:

attention_output – The result of the computation, of shape (B, N, V), where N is the number of heads and V is the value dimensionality.

Return type:

tensorflow.Tensor

get_config()

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

class mt.tf.keras_layers.MHAPool2D(*args, **kwargs)

Pooling in 2D using Keras-based self-attention.

The layer takes as input a high-dim image tensor of shape [B, H, W, D] where B is the batch size, H and W are the grid resolution, and D is the (high) number of channels. First, it pools the tensor down to an unprojected query tensor of shape [B, H2, W2, D] using max or avg pooling. Second, it 2D-convolves the unprojected query tensor, the input tensor and the input tensor to the query tensor of shape [B, H2, W2, N*K], the key tensor of shape [B, H, W, N*K] and the value tensor of shape [B, H, W, N*V] where N is the number of heads, K is the key dimensionality and V is the value dimensionality. In the absence of V, V is set to K. Third, it divides query with sqrt(K). Fourth, it splits the num_heads dimension out of the last dimension from all 3 tensors. Fifth, in a single einsum op of query and key, it contracts K, makes an outer-product of [H2,W2] with [H,W], and runs through all B and N, outputing a prod tensor of shape [B, H2, W2, H, W, N]. Fifth, it merges H with W in both prod and value resulting in shapes [B, H2, W2, H*W, N] and [B, H*W, N, V] respectively. Sixth, prod is softmaxed along the H*W axis. Seventh, in another einsum op of prod and value, it contracts H*W while running through all other indices, outputing an attention tensor of shape [B, H2, W2, N, V]. Finally, it merges N with V and returns the result.

Parameters:
  • num_heads (int) – Number of attention heads.

  • key_dim (int) – Size of each attention head for query and key.

  • value_dim (int, optional) – Size of each attention head for value.

  • pooling ({'max', 'avg'}) – type of 2D pooling

  • pool_size (int or tuple) – integer or tuple of 2 integers, factors by which to downscale (vertical, horizontal). (2, 2) will halve the input in both spatial dimension. If only one integer is specified, the same window length will be used for both dimensions.

  • use_bias (bool) – Whether the convolution layers use bias vectors/matrices.

  • activation (object) – activation for the value convolution

  • kernel_initializer (object) – Initializer for the convolutional layer kernels.

  • bias_initializer (object) – Initializer for the convolutional layer biases.

  • kernel_regularizer (object) – Regularizer for the convolutional layer kernels.

  • bias_regularizer (object) – Regularizer for the convolutional layer biases.

  • kernel_constraint (object) – Contraint function applied to the layer kernels.

  • bias_constraint (object) – Contraint function applied to the layer biases.

  • dropout (float) – dropout probability

Examples

>>> layer = MHAPool2D(num_heads=3, key_dim=40, value_dim=80)
>>> input_tensor = tf.keras.Input(shape=[8, 8, 160])
>>> output_tensor = layer(input_tensor)
>>> print(output_tensor.shape)
(None, 4, 4, 240)

Inheritance

digraph inheritance04adf65200 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoTrackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Manages dependencies on other objects."]; "Trackable" -> "AutoTrackable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Layer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This is the class from which all layers inherit."]; "Module" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Chooses between Keras v1 and v2 Layer class."]; "MHAPool2D" [URL="#mt.tf.keras_layers.MHAPool2D",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Pooling in 2D using Keras-based self-attention."]; "Layer" -> "MHAPool2D" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Module" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base neural network module class."]; "AutoTrackable" -> "Module" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Trackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for `Trackable` objects without automatic dependencies."]; }
call(blob, training=None, return_attention_scores: bool = False)

The call function.

Parameters:
  • blob (tensorflow.Tensor) – input Tensor of shape (B, H, W, D).

  • training (bool) – Whether the layer should behave in training mode or in inference mode.

  • return_attention_scores (bool) – Whether to return the attention scores as well.

Returns:

  • attention_output (tensorflow.Tensor) – The result of the computation, of shape (B, H2, W2, N*V), where H2 and W2 represent the downsampled resolution, N is the number of heads and V is the value dimensionality.

  • attention_scores (tensorflow.Tensor) – Multi-headed attention weights, of shape (B, H2, W2, H*W, N). Only available if return_attention_scores is True.

get_config()

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

class mt.tf.keras_layers.DUCLayer(*args, **kwargs)

Base layer for all DUC layer implementations.

Parameters:
  • kernel_size (int or tuple or list) – An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.

  • kernel_initializer (object) – Initializer for the convolutional kernels.

  • bias_initializer (object) – Initializer for the convolutional biases.

  • kernel_regularizer (object) – Regularizer for the convolutional kernels.

  • bias_regularizer (object) – Regularizer for the convolutional biases.

  • kernel_constraint (object) – Contraint function applied to the convolutional layer kernels.

  • bias_constraint (object) – Contraint function applied to the convolutional layer biases.

Inheritance

digraph inheritance530c50278e { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoTrackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Manages dependencies on other objects."]; "Trackable" -> "AutoTrackable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DUCLayer" [URL="#mt.tf.keras_layers.DUCLayer",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Base layer for all DUC layer implementations."]; "Layer" -> "DUCLayer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Layer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This is the class from which all layers inherit."]; "Module" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Chooses between Keras v1 and v2 Layer class."]; "Module" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base neural network module class."]; "AutoTrackable" -> "Module" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Trackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for `Trackable` objects without automatic dependencies."]; }
get_config()

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

class mt.tf.keras_layers.Downsize2D(*args, **kwargs)

Downsizing along the x-axis and the y-axis using convolutions of residuals.

Downsizing means halving the width and the height and doubling the number of channels.

This layer is supposed to be nearly an inverse of the Upsize2D layer.

Parameters:
  • input_dim (int) – the dimensionality (number of channels) of each input pixel

  • expansion_factor (int) – the coefficient defining the number of hidden images per cell needed.

  • kernel_size (int or tuple or list) – An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.

  • kernel_initializer (object) – Initializer for the convolutional kernels.

  • bias_initializer (object) – Initializer for the convolutional biases.

  • kernel_regularizer (object) – Regularizer for the convolutional kernels.

  • bias_regularizer (object) – Regularizer for the convolutional biases.

  • kernel_constraint (object) – Contraint function applied to the convolutional layer kernels.

  • bias_constraint (object) – Contraint function applied to the convolutional layer biases.

Inheritance

digraph inheritance20dd28c3a7 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoTrackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Manages dependencies on other objects."]; "Trackable" -> "AutoTrackable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DUCLayer" [URL="#mt.tf.keras_layers.DUCLayer",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Base layer for all DUC layer implementations."]; "Layer" -> "DUCLayer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Downsize2D" [URL="#mt.tf.keras_layers.Downsize2D",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Downsizing along the x-axis and the y-axis using convolutions of residuals."]; "DUCLayer" -> "Downsize2D" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Layer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This is the class from which all layers inherit."]; "Module" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Chooses between Keras v1 and v2 Layer class."]; "Module" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base neural network module class."]; "AutoTrackable" -> "Module" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Trackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for `Trackable` objects without automatic dependencies."]; }
call(x, training: bool = False)

This is where the layer’s logic lives.

The call() method may not create state (except in its first invocation, wrapping the creation of variables or other resources in tf.init_scope()). It is recommended to create state in __init__(), or the build() method that is called automatically before call() executes the first time.

Parameters:
  • inputs

    Input tensor, or dict/list/tuple of input tensors. The first positional inputs argument is subject to special rules: - inputs must be explicitly passed. A layer cannot have zero

    arguments, and inputs cannot be provided via the default value of a keyword argument.

    • NumPy array or Python scalar values in inputs get cast as tensors.

    • Keras mask metadata is only collected from inputs.

    • Layers are built (build(input_shape) method) using shape info from inputs only.

    • input_spec compatibility is only checked against inputs.

    • Mixed precision input casting is only applied to inputs. If a layer has tensor arguments in *args or **kwargs, their casting behavior in mixed precision should be handled manually.

    • The SavedModel input specification is generated using inputs only.

    • Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for inputs and not for tensors in positional and keyword arguments.

  • *args – Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above.

  • **kwargs

    Additional keyword arguments. May contain tensors, although this is not recommended, for the reasons above. The following optional keyword arguments are reserved: - training: Boolean scalar tensor of Python boolean indicating

    whether the call is meant for training or inference.

    • mask: Boolean input mask. If the layer’s call() method takes a mask argument, its default value will be set to the mask generated for inputs by the previous layer (if input did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).

Returns:

A tensor or list/tuple of tensors.

compute_output_shape(input_shape)

Computes the output shape of the layer.

This method will cause the layer’s state to be built, if that has not happened before. This requires that the layer will later be used with inputs that match the input shape provided here.

Parameters:

input_shape – Shape tuple (tuple of integers) or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns:

An input shape tuple.

get_config()

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

class mt.tf.keras_layers.Upsize2D(*args, **kwargs)

Upsizing along the x-axis and the y-axis using convolutions of residuals.

Upsizing means doubling the width and the height and halving the number of channels.

Input at each grid cell is a pair of (avg, res) images at resolution (H,W,C). The pair is transformed to 4*expansion_factor hidden images and then 4 residual images (res1, res2, res3, res4). Then, avg is added to the 4 residual images, forming at each cell a 2x2 block of images (avg+res1, avg+res2, avg+res3, avg+res4). Finally, the new blocks across the whole tensor form a new grid, doubling the height and width. Note that each avg+resK image serves as a pair of average and residual images in the higher resolution.

Parameters:
  • input_dim (int) – the dimensionality of each input pixel. Must be even.

  • expansion_factor (int) – the coefficient defining the number of hidden images per cell needed.

  • kernel_size (int or tuple or list) – An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.

  • kernel_initializer (object) – Initializer for the convolutional kernels.

  • bias_initializer (object) – Initializer for the convolutional biases.

  • kernel_regularizer (object) – Regularizer for the convolutional kernels.

  • bias_regularizer (object) – Regularizer for the convolutional biases.

  • kernel_constraint (object) – Contraint function applied to the convolutional layer kernels.

  • bias_constraint (object) – Contraint function applied to the convolutional layer biases.

Inheritance

digraph inheritance8132c823b2 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoTrackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Manages dependencies on other objects."]; "Trackable" -> "AutoTrackable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DUCLayer" [URL="#mt.tf.keras_layers.DUCLayer",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Base layer for all DUC layer implementations."]; "Layer" -> "DUCLayer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Layer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This is the class from which all layers inherit."]; "Module" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Chooses between Keras v1 and v2 Layer class."]; "Module" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base neural network module class."]; "AutoTrackable" -> "Module" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Trackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for `Trackable` objects without automatic dependencies."]; "Upsize2D" [URL="#mt.tf.keras_layers.Upsize2D",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Upsizing along the x-axis and the y-axis using convolutions of residuals."]; "DUCLayer" -> "Upsize2D" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
call(x, training: bool = False)

This is where the layer’s logic lives.

The call() method may not create state (except in its first invocation, wrapping the creation of variables or other resources in tf.init_scope()). It is recommended to create state in __init__(), or the build() method that is called automatically before call() executes the first time.

Parameters:
  • inputs

    Input tensor, or dict/list/tuple of input tensors. The first positional inputs argument is subject to special rules: - inputs must be explicitly passed. A layer cannot have zero

    arguments, and inputs cannot be provided via the default value of a keyword argument.

    • NumPy array or Python scalar values in inputs get cast as tensors.

    • Keras mask metadata is only collected from inputs.

    • Layers are built (build(input_shape) method) using shape info from inputs only.

    • input_spec compatibility is only checked against inputs.

    • Mixed precision input casting is only applied to inputs. If a layer has tensor arguments in *args or **kwargs, their casting behavior in mixed precision should be handled manually.

    • The SavedModel input specification is generated using inputs only.

    • Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for inputs and not for tensors in positional and keyword arguments.

  • *args – Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above.

  • **kwargs

    Additional keyword arguments. May contain tensors, although this is not recommended, for the reasons above. The following optional keyword arguments are reserved: - training: Boolean scalar tensor of Python boolean indicating

    whether the call is meant for training or inference.

    • mask: Boolean input mask. If the layer’s call() method takes a mask argument, its default value will be set to the mask generated for inputs by the previous layer (if input did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).

Returns:

A tensor or list/tuple of tensors.

compute_output_shape(input_shape)

Computes the output shape of the layer.

This method will cause the layer’s state to be built, if that has not happened before. This requires that the layer will later be used with inputs that match the input shape provided here.

Parameters:

input_shape – Shape tuple (tuple of integers) or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns:

An input shape tuple.

get_config()

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

class mt.tf.keras_layers.Downsize2D_V2(*args, **kwargs)

Downsizing along the x-axis and the y-axis using convolutions of residuals.

Downsizing means halving the width and the height and doubling the number of channels.

This layer is supposed to be nearly an inverse of the Upsize2D layer.

Input dimensionality consists of image dimensionality and residual dimensionality.

Parameters:
  • img_dim (int) – the image dimensionality

  • res_dim (int) – the residual dimensionality

  • expansion_factor (int) – the coefficient defining the number of hidden images per cell needed.

  • kernel_size (int or tuple or list) – An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.

  • kernel_initializer (object) – Initializer for the convolutional kernels.

  • bias_initializer (object) – Initializer for the convolutional biases.

  • kernel_regularizer (object) – Regularizer for the convolutional kernels.

  • bias_regularizer (object) – Regularizer for the convolutional biases.

  • kernel_constraint (object) – Contraint function applied to the convolutional layer kernels.

  • bias_constraint (object) – Contraint function applied to the convolutional layer biases.

  • projection_uses_bias (bool) – whether or not the projection convolution layer uses a bias vector

Inheritance

digraph inheritancef707b0c641 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoTrackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Manages dependencies on other objects."]; "Trackable" -> "AutoTrackable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DUCLayer" [URL="#mt.tf.keras_layers.DUCLayer",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Base layer for all DUC layer implementations."]; "Layer" -> "DUCLayer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Downsize2D_V2" [URL="#mt.tf.keras_layers.Downsize2D_V2",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Downsizing along the x-axis and the y-axis using convolutions of residuals."]; "DUCLayer" -> "Downsize2D_V2" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Layer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This is the class from which all layers inherit."]; "Module" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Chooses between Keras v1 and v2 Layer class."]; "Module" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base neural network module class."]; "AutoTrackable" -> "Module" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Trackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for `Trackable` objects without automatic dependencies."]; }
call(x, training: bool = False)

This is where the layer’s logic lives.

The call() method may not create state (except in its first invocation, wrapping the creation of variables or other resources in tf.init_scope()). It is recommended to create state in __init__(), or the build() method that is called automatically before call() executes the first time.

Parameters:
  • inputs

    Input tensor, or dict/list/tuple of input tensors. The first positional inputs argument is subject to special rules: - inputs must be explicitly passed. A layer cannot have zero

    arguments, and inputs cannot be provided via the default value of a keyword argument.

    • NumPy array or Python scalar values in inputs get cast as tensors.

    • Keras mask metadata is only collected from inputs.

    • Layers are built (build(input_shape) method) using shape info from inputs only.

    • input_spec compatibility is only checked against inputs.

    • Mixed precision input casting is only applied to inputs. If a layer has tensor arguments in *args or **kwargs, their casting behavior in mixed precision should be handled manually.

    • The SavedModel input specification is generated using inputs only.

    • Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for inputs and not for tensors in positional and keyword arguments.

  • *args – Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above.

  • **kwargs

    Additional keyword arguments. May contain tensors, although this is not recommended, for the reasons above. The following optional keyword arguments are reserved: - training: Boolean scalar tensor of Python boolean indicating

    whether the call is meant for training or inference.

    • mask: Boolean input mask. If the layer’s call() method takes a mask argument, its default value will be set to the mask generated for inputs by the previous layer (if input did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).

Returns:

A tensor or list/tuple of tensors.

compute_output_shape(input_shape)

Computes the output shape of the layer.

This method will cause the layer’s state to be built, if that has not happened before. This requires that the layer will later be used with inputs that match the input shape provided here.

Parameters:

input_shape – Shape tuple (tuple of integers) or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns:

An input shape tuple.

get_config()

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

class mt.tf.keras_layers.Upsize2D_V2(*args, **kwargs)

Upsizing along the x-axis and the y-axis using convolutions of residuals.

Upsizing means doubling the width and the height and halving the number of channels.

Input at each grid cell is a pair of (avg, res) images at resolution (H,W,C). The pair is transformed to 4*expansion_factor hidden images and then 4 residual images (res1, res2, res3, res4). Then, avg is added to the 4 residual images, forming at each cell a 2x2 block of images (avg+res1, avg+res2, avg+res3, avg+res4). Finally, the new blocks across the whole tensor form a new grid, doubling the height and width. Note that each avg+resK image serves as a pair of average and residual images in the higher resolution.

Input dimensionality consists of image dimensionality and residual dimensionality. It must be even.

Parameters:
  • img_dim (int) – the image dimensionality.

  • res_dim (int) – the residual dimensionality.

  • expansion_factor (int) – the coefficient defining the number of hidden images per cell needed.

  • kernel_size (int or tuple or list) – An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.

  • kernel_initializer (object) – Initializer for the convolutional kernels.

  • bias_initializer (object) – Initializer for the convolutional biases.

  • kernel_regularizer (object) – Regularizer for the convolutional kernels.

  • bias_regularizer (object) – Regularizer for the convolutional biases.

  • kernel_constraint (object) – Contraint function applied to the convolutional layer kernels.

  • bias_constraint (object) – Contraint function applied to the convolutional layer biases.

Inheritance

digraph inheritancec8cb91f7d7 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoTrackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Manages dependencies on other objects."]; "Trackable" -> "AutoTrackable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DUCLayer" [URL="#mt.tf.keras_layers.DUCLayer",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Base layer for all DUC layer implementations."]; "Layer" -> "DUCLayer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Layer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This is the class from which all layers inherit."]; "Module" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Chooses between Keras v1 and v2 Layer class."]; "Module" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base neural network module class."]; "AutoTrackable" -> "Module" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Trackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for `Trackable` objects without automatic dependencies."]; "Upsize2D_V2" [URL="#mt.tf.keras_layers.Upsize2D_V2",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Upsizing along the x-axis and the y-axis using convolutions of residuals."]; "DUCLayer" -> "Upsize2D_V2" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
call(x, training: bool = False)

This is where the layer’s logic lives.

The call() method may not create state (except in its first invocation, wrapping the creation of variables or other resources in tf.init_scope()). It is recommended to create state in __init__(), or the build() method that is called automatically before call() executes the first time.

Parameters:
  • inputs

    Input tensor, or dict/list/tuple of input tensors. The first positional inputs argument is subject to special rules: - inputs must be explicitly passed. A layer cannot have zero

    arguments, and inputs cannot be provided via the default value of a keyword argument.

    • NumPy array or Python scalar values in inputs get cast as tensors.

    • Keras mask metadata is only collected from inputs.

    • Layers are built (build(input_shape) method) using shape info from inputs only.

    • input_spec compatibility is only checked against inputs.

    • Mixed precision input casting is only applied to inputs. If a layer has tensor arguments in *args or **kwargs, their casting behavior in mixed precision should be handled manually.

    • The SavedModel input specification is generated using inputs only.

    • Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for inputs and not for tensors in positional and keyword arguments.

  • *args – Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above.

  • **kwargs

    Additional keyword arguments. May contain tensors, although this is not recommended, for the reasons above. The following optional keyword arguments are reserved: - training: Boolean scalar tensor of Python boolean indicating

    whether the call is meant for training or inference.

    • mask: Boolean input mask. If the layer’s call() method takes a mask argument, its default value will be set to the mask generated for inputs by the previous layer (if input did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).

Returns:

A tensor or list/tuple of tensors.

compute_output_shape(input_shape)

Computes the output shape of the layer.

This method will cause the layer’s state to be built, if that has not happened before. This requires that the layer will later be used with inputs that match the input shape provided here.

Parameters:

input_shape – Shape tuple (tuple of integers) or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns:

An input shape tuple.

get_config()

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

class mt.tf.keras_layers.Downsize2D_V3(*args, **kwargs)

Downsizing along the x-axis and the y-axis using convolutions of residuals.

Downsizing means halving the width and the height and doubling the number of channels.

TBC

This layer is supposed to be nearly an inverse of the Upsize2D layer.

Input dimensionality consists of image dimensionality and residual dimensionality.

Parameters:
  • img_dim (int) – the image dimensionality

  • res_dim (int) – the residual dimensionality

  • kernel_size (int or tuple or list) – An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.

  • kernel_initializer (object) – Initializer for the convolutional kernels.

  • bias_initializer (object) – Initializer for the convolutional biases.

  • kernel_regularizer (object) – Regularizer for the convolutional kernels.

  • bias_regularizer (object) – Regularizer for the convolutional biases.

  • kernel_constraint (object) – Contraint function applied to the convolutional layer kernels.

  • bias_constraint (object) – Contraint function applied to the convolutional layer biases.

Inheritance

digraph inheritancefd536e0c02 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoTrackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Manages dependencies on other objects."]; "Trackable" -> "AutoTrackable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DUCLayer" [URL="#mt.tf.keras_layers.DUCLayer",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Base layer for all DUC layer implementations."]; "Layer" -> "DUCLayer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Downsize2D_V3" [URL="#mt.tf.keras_layers.Downsize2D_V3",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Downsizing along the x-axis and the y-axis using convolutions of residuals."]; "DUCLayer" -> "Downsize2D_V3" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Layer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This is the class from which all layers inherit."]; "Module" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Chooses between Keras v1 and v2 Layer class."]; "Module" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base neural network module class."]; "AutoTrackable" -> "Module" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Trackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for `Trackable` objects without automatic dependencies."]; }
call(x, training: bool = False)

This is where the layer’s logic lives.

The call() method may not create state (except in its first invocation, wrapping the creation of variables or other resources in tf.init_scope()). It is recommended to create state in __init__(), or the build() method that is called automatically before call() executes the first time.

Parameters:
  • inputs

    Input tensor, or dict/list/tuple of input tensors. The first positional inputs argument is subject to special rules: - inputs must be explicitly passed. A layer cannot have zero

    arguments, and inputs cannot be provided via the default value of a keyword argument.

    • NumPy array or Python scalar values in inputs get cast as tensors.

    • Keras mask metadata is only collected from inputs.

    • Layers are built (build(input_shape) method) using shape info from inputs only.

    • input_spec compatibility is only checked against inputs.

    • Mixed precision input casting is only applied to inputs. If a layer has tensor arguments in *args or **kwargs, their casting behavior in mixed precision should be handled manually.

    • The SavedModel input specification is generated using inputs only.

    • Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for inputs and not for tensors in positional and keyword arguments.

  • *args – Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above.

  • **kwargs

    Additional keyword arguments. May contain tensors, although this is not recommended, for the reasons above. The following optional keyword arguments are reserved: - training: Boolean scalar tensor of Python boolean indicating

    whether the call is meant for training or inference.

    • mask: Boolean input mask. If the layer’s call() method takes a mask argument, its default value will be set to the mask generated for inputs by the previous layer (if input did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).

Returns:

A tensor or list/tuple of tensors.

compute_output_shape(input_shape)

Computes the output shape of the layer.

This method will cause the layer’s state to be built, if that has not happened before. This requires that the layer will later be used with inputs that match the input shape provided here.

Parameters:

input_shape – Shape tuple (tuple of integers) or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns:

An input shape tuple.

get_config()

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

mt.tf.keras_layers.Downsize2D_V4

alias of Downsize2D_V3

class mt.tf.keras_layers.DownsizeX2D(*args, **kwargs)

Downsizing along the x-axis and the y-axis using convolutions of residuals.

Downsizing means halving the width and the height and doubling the number of channels.

TBC

This layer is supposed to be nearly an inverse of the Upsize2D layer.

Input dimensionality consists of image dimensionality and residual dimensionality.

Parameters:
  • img_dim (int) – the image dimensionality

  • res_dim (int) – the residual dimensionality

  • kernel_size (int or tuple or list) – An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.

  • kernel_initializer (object) – Initializer for the convolutional kernels.

  • bias_initializer (object) – Initializer for the convolutional biases.

  • kernel_regularizer (object) – Regularizer for the convolutional kernels.

  • bias_regularizer (object) – Regularizer for the convolutional biases.

  • kernel_constraint (object) – Contraint function applied to the convolutional layer kernels.

  • bias_constraint (object) – Contraint function applied to the convolutional layer biases.

Inheritance

digraph inheritance906bfcb9a0 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoTrackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Manages dependencies on other objects."]; "Trackable" -> "AutoTrackable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DUCLayer" [URL="#mt.tf.keras_layers.DUCLayer",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Base layer for all DUC layer implementations."]; "Layer" -> "DUCLayer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DUCLayerV5" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Downsizing along the x-axis and the y-axis using convolutions of residuals."]; "DUCLayer" -> "DUCLayerV5" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DownsizeX2D" [URL="#mt.tf.keras_layers.DownsizeX2D",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Downsizing along the x-axis and the y-axis using convolutions of residuals."]; "DUCLayerV5" -> "DownsizeX2D" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Layer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This is the class from which all layers inherit."]; "Module" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Chooses between Keras v1 and v2 Layer class."]; "Module" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base neural network module class."]; "AutoTrackable" -> "Module" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Trackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for `Trackable` objects without automatic dependencies."]; }
call(x, training: bool = False)

This is where the layer’s logic lives.

The call() method may not create state (except in its first invocation, wrapping the creation of variables or other resources in tf.init_scope()). It is recommended to create state in __init__(), or the build() method that is called automatically before call() executes the first time.

Parameters:
  • inputs

    Input tensor, or dict/list/tuple of input tensors. The first positional inputs argument is subject to special rules: - inputs must be explicitly passed. A layer cannot have zero

    arguments, and inputs cannot be provided via the default value of a keyword argument.

    • NumPy array or Python scalar values in inputs get cast as tensors.

    • Keras mask metadata is only collected from inputs.

    • Layers are built (build(input_shape) method) using shape info from inputs only.

    • input_spec compatibility is only checked against inputs.

    • Mixed precision input casting is only applied to inputs. If a layer has tensor arguments in *args or **kwargs, their casting behavior in mixed precision should be handled manually.

    • The SavedModel input specification is generated using inputs only.

    • Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for inputs and not for tensors in positional and keyword arguments.

  • *args – Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above.

  • **kwargs

    Additional keyword arguments. May contain tensors, although this is not recommended, for the reasons above. The following optional keyword arguments are reserved: - training: Boolean scalar tensor of Python boolean indicating

    whether the call is meant for training or inference.

    • mask: Boolean input mask. If the layer’s call() method takes a mask argument, its default value will be set to the mask generated for inputs by the previous layer (if input did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).

Returns:

A tensor or list/tuple of tensors.

class mt.tf.keras_layers.UpsizeX2D(*args, **kwargs)

Downsizing along the x-axis and the y-axis using convolutions of residuals.

Downsizing means halving the width and the height and doubling the number of channels.

TBC

This layer is supposed to be nearly an inverse of the Upsize2D layer.

Input dimensionality consists of image dimensionality and residual dimensionality.

Parameters:
  • img_dim (int) – the image dimensionality

  • res_dim (int) – the residual dimensionality

  • kernel_size (int or tuple or list) – An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.

  • kernel_initializer (object) – Initializer for the convolutional kernels.

  • bias_initializer (object) – Initializer for the convolutional biases.

  • kernel_regularizer (object) – Regularizer for the convolutional kernels.

  • bias_regularizer (object) – Regularizer for the convolutional biases.

  • kernel_constraint (object) – Contraint function applied to the convolutional layer kernels.

  • bias_constraint (object) – Contraint function applied to the convolutional layer biases.

Inheritance

digraph inheritance358cbf3819 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoTrackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Manages dependencies on other objects."]; "Trackable" -> "AutoTrackable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DUCLayer" [URL="#mt.tf.keras_layers.DUCLayer",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Base layer for all DUC layer implementations."]; "Layer" -> "DUCLayer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DUCLayerV5" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Downsizing along the x-axis and the y-axis using convolutions of residuals."]; "DUCLayer" -> "DUCLayerV5" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Layer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This is the class from which all layers inherit."]; "Module" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Chooses between Keras v1 and v2 Layer class."]; "Module" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base neural network module class."]; "AutoTrackable" -> "Module" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Trackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for `Trackable` objects without automatic dependencies."]; "UpsizeX2D" [URL="#mt.tf.keras_layers.UpsizeX2D",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Downsizing along the x-axis and the y-axis using convolutions of residuals."]; "DUCLayerV5" -> "UpsizeX2D" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
call(x, training: bool = False)

This is where the layer’s logic lives.

The call() method may not create state (except in its first invocation, wrapping the creation of variables or other resources in tf.init_scope()). It is recommended to create state in __init__(), or the build() method that is called automatically before call() executes the first time.

Parameters:
  • inputs

    Input tensor, or dict/list/tuple of input tensors. The first positional inputs argument is subject to special rules: - inputs must be explicitly passed. A layer cannot have zero

    arguments, and inputs cannot be provided via the default value of a keyword argument.

    • NumPy array or Python scalar values in inputs get cast as tensors.

    • Keras mask metadata is only collected from inputs.

    • Layers are built (build(input_shape) method) using shape info from inputs only.

    • input_spec compatibility is only checked against inputs.

    • Mixed precision input casting is only applied to inputs. If a layer has tensor arguments in *args or **kwargs, their casting behavior in mixed precision should be handled manually.

    • The SavedModel input specification is generated using inputs only.

    • Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for inputs and not for tensors in positional and keyword arguments.

  • *args – Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above.

  • **kwargs

    Additional keyword arguments. May contain tensors, although this is not recommended, for the reasons above. The following optional keyword arguments are reserved: - training: Boolean scalar tensor of Python boolean indicating

    whether the call is meant for training or inference.

    • mask: Boolean input mask. If the layer’s call() method takes a mask argument, its default value will be set to the mask generated for inputs by the previous layer (if input did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).

Returns:

A tensor or list/tuple of tensors.

class mt.tf.keras_layers.DownsizeY2D(*args, **kwargs)

Downsizing along the x-axis and the y-axis using convolutions of residuals.

Downsizing means halving the width and the height and doubling the number of channels.

TBC

This layer is supposed to be nearly an inverse of the Upsize2D layer.

Input dimensionality consists of image dimensionality and residual dimensionality.

Parameters:
  • img_dim (int) – the image dimensionality

  • res_dim (int) – the residual dimensionality

  • kernel_size (int or tuple or list) – An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.

  • kernel_initializer (object) – Initializer for the convolutional kernels.

  • bias_initializer (object) – Initializer for the convolutional biases.

  • kernel_regularizer (object) – Regularizer for the convolutional kernels.

  • bias_regularizer (object) – Regularizer for the convolutional biases.

  • kernel_constraint (object) – Contraint function applied to the convolutional layer kernels.

  • bias_constraint (object) – Contraint function applied to the convolutional layer biases.

Inheritance

digraph inheritance0a40581503 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoTrackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Manages dependencies on other objects."]; "Trackable" -> "AutoTrackable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DUCLayer" [URL="#mt.tf.keras_layers.DUCLayer",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Base layer for all DUC layer implementations."]; "Layer" -> "DUCLayer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DUCLayerV5" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Downsizing along the x-axis and the y-axis using convolutions of residuals."]; "DUCLayer" -> "DUCLayerV5" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DownsizeY2D" [URL="#mt.tf.keras_layers.DownsizeY2D",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Downsizing along the x-axis and the y-axis using convolutions of residuals."]; "DUCLayerV5" -> "DownsizeY2D" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Layer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This is the class from which all layers inherit."]; "Module" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Chooses between Keras v1 and v2 Layer class."]; "Module" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base neural network module class."]; "AutoTrackable" -> "Module" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Trackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for `Trackable` objects without automatic dependencies."]; }
call(x, training: bool = False)

This is where the layer’s logic lives.

The call() method may not create state (except in its first invocation, wrapping the creation of variables or other resources in tf.init_scope()). It is recommended to create state in __init__(), or the build() method that is called automatically before call() executes the first time.

Parameters:
  • inputs

    Input tensor, or dict/list/tuple of input tensors. The first positional inputs argument is subject to special rules: - inputs must be explicitly passed. A layer cannot have zero

    arguments, and inputs cannot be provided via the default value of a keyword argument.

    • NumPy array or Python scalar values in inputs get cast as tensors.

    • Keras mask metadata is only collected from inputs.

    • Layers are built (build(input_shape) method) using shape info from inputs only.

    • input_spec compatibility is only checked against inputs.

    • Mixed precision input casting is only applied to inputs. If a layer has tensor arguments in *args or **kwargs, their casting behavior in mixed precision should be handled manually.

    • The SavedModel input specification is generated using inputs only.

    • Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for inputs and not for tensors in positional and keyword arguments.

  • *args – Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above.

  • **kwargs

    Additional keyword arguments. May contain tensors, although this is not recommended, for the reasons above. The following optional keyword arguments are reserved: - training: Boolean scalar tensor of Python boolean indicating

    whether the call is meant for training or inference.

    • mask: Boolean input mask. If the layer’s call() method takes a mask argument, its default value will be set to the mask generated for inputs by the previous layer (if input did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).

Returns:

A tensor or list/tuple of tensors.

class mt.tf.keras_layers.UpsizeY2D(*args, **kwargs)

Downsizing along the x-axis and the y-axis using convolutions of residuals.

Downsizing means halving the width and the height and doubling the number of channels.

TBC

This layer is supposed to be nearly an inverse of the Upsize2D layer.

Input dimensionality consists of image dimensionality and residual dimensionality.

Parameters:
  • img_dim (int) – the image dimensionality

  • res_dim (int) – the residual dimensionality

  • kernel_size (int or tuple or list) – An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.

  • kernel_initializer (object) – Initializer for the convolutional kernels.

  • bias_initializer (object) – Initializer for the convolutional biases.

  • kernel_regularizer (object) – Regularizer for the convolutional kernels.

  • bias_regularizer (object) – Regularizer for the convolutional biases.

  • kernel_constraint (object) – Contraint function applied to the convolutional layer kernels.

  • bias_constraint (object) – Contraint function applied to the convolutional layer biases.

Inheritance

digraph inheritance344fb5e316 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoTrackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Manages dependencies on other objects."]; "Trackable" -> "AutoTrackable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DUCLayer" [URL="#mt.tf.keras_layers.DUCLayer",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Base layer for all DUC layer implementations."]; "Layer" -> "DUCLayer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DUCLayerV5" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Downsizing along the x-axis and the y-axis using convolutions of residuals."]; "DUCLayer" -> "DUCLayerV5" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Layer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This is the class from which all layers inherit."]; "Module" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Chooses between Keras v1 and v2 Layer class."]; "Module" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base neural network module class."]; "AutoTrackable" -> "Module" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Trackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for `Trackable` objects without automatic dependencies."]; "UpsizeY2D" [URL="#mt.tf.keras_layers.UpsizeY2D",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Downsizing along the x-axis and the y-axis using convolutions of residuals."]; "DUCLayerV5" -> "UpsizeY2D" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
call(x, training: bool = False)

This is where the layer’s logic lives.

The call() method may not create state (except in its first invocation, wrapping the creation of variables or other resources in tf.init_scope()). It is recommended to create state in __init__(), or the build() method that is called automatically before call() executes the first time.

Parameters:
  • inputs

    Input tensor, or dict/list/tuple of input tensors. The first positional inputs argument is subject to special rules: - inputs must be explicitly passed. A layer cannot have zero

    arguments, and inputs cannot be provided via the default value of a keyword argument.

    • NumPy array or Python scalar values in inputs get cast as tensors.

    • Keras mask metadata is only collected from inputs.

    • Layers are built (build(input_shape) method) using shape info from inputs only.

    • input_spec compatibility is only checked against inputs.

    • Mixed precision input casting is only applied to inputs. If a layer has tensor arguments in *args or **kwargs, their casting behavior in mixed precision should be handled manually.

    • The SavedModel input specification is generated using inputs only.

    • Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for inputs and not for tensors in positional and keyword arguments.

  • *args – Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above.

  • **kwargs

    Additional keyword arguments. May contain tensors, although this is not recommended, for the reasons above. The following optional keyword arguments are reserved: - training: Boolean scalar tensor of Python boolean indicating

    whether the call is meant for training or inference.

    • mask: Boolean input mask. If the layer’s call() method takes a mask argument, its default value will be set to the mask generated for inputs by the previous layer (if input did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).

Returns:

A tensor or list/tuple of tensors.

class mt.tf.keras_layers.Counter(*args, **kwargs)

A layer that counts from 0 during training and does nothing during inference.

Inheritance

digraph inheritance40accdb559 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoTrackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Manages dependencies on other objects."]; "Trackable" -> "AutoTrackable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Counter" [URL="#mt.tf.keras_layers.Counter",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A layer that counts from 0 during training and does nothing during inference."]; "Layer" -> "Counter" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Layer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This is the class from which all layers inherit."]; "Module" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" -> "Layer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LayerVersionSelector" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Chooses between Keras v1 and v2 Layer class."]; "Module" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base neural network module class."]; "AutoTrackable" -> "Module" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Trackable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for `Trackable` objects without automatic dependencies."]; }
build(input_shape)

Creates the variables of the layer (optional, for subclass implementers).

This is a method that implementers of subclasses of Layer or Model can override if they need a state-creation step in-between layer instantiation and layer call. It is invoked automatically before the first execution of call().

This is typically used to create the weights of Layer subclasses (at the discretion of the subclass implementer).

Parameters:

input_shape – Instance of TensorShape, or list of instances of TensorShape if the layer expects a list of inputs (one instance per input).

call(x, training: bool = False)

This is where the layer’s logic lives.

The call() method may not create state (except in its first invocation, wrapping the creation of variables or other resources in tf.init_scope()). It is recommended to create state in __init__(), or the build() method that is called automatically before call() executes the first time.

Parameters:
  • inputs

    Input tensor, or dict/list/tuple of input tensors. The first positional inputs argument is subject to special rules: - inputs must be explicitly passed. A layer cannot have zero

    arguments, and inputs cannot be provided via the default value of a keyword argument.

    • NumPy array or Python scalar values in inputs get cast as tensors.

    • Keras mask metadata is only collected from inputs.

    • Layers are built (build(input_shape) method) using shape info from inputs only.

    • input_spec compatibility is only checked against inputs.

    • Mixed precision input casting is only applied to inputs. If a layer has tensor arguments in *args or **kwargs, their casting behavior in mixed precision should be handled manually.

    • The SavedModel input specification is generated using inputs only.

    • Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for inputs and not for tensors in positional and keyword arguments.

  • *args – Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above.

  • **kwargs

    Additional keyword arguments. May contain tensors, although this is not recommended, for the reasons above. The following optional keyword arguments are reserved: - training: Boolean scalar tensor of Python boolean indicating

    whether the call is meant for training or inference.

    • mask: Boolean input mask. If the layer’s call() method takes a mask argument, its default value will be set to the mask generated for inputs by the previous layer (if input did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).

Returns:

A tensor or list/tuple of tensors.

compute_output_shape(input_shape)

Computes the output shape of the layer.

This method will cause the layer’s state to be built, if that has not happened before. This requires that the layer will later be used with inputs that match the input shape provided here.

Parameters:

input_shape – Shape tuple (tuple of integers) or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns:

An input shape tuple.