das.tcn.tcn_new#

class das.tcn.tcn_new.ResidualBlock(*args, **kwargs)[source]#

Defines the residual block for the WaveNet TCN

Parameters
  • x – The previous layer in the model

  • training – boolean indicating whether the layer should behave in training mode or in inference mode

  • dilation_rate – The dilation power of 2 we are using for this residual block

  • nb_filters – The number of convolutional filters to use in this block

  • kernel_size – The size of the convolutional kernel

  • padding – The padding used in the convolutional layers, ‘same’ or ‘causal’.

  • activation – The final activation used in o = Activation(x + F(x))

  • dropout_rate – Float between 0 and 1. Fraction of the input units to drop.

  • kernel_initializer – Initializer for the kernel weights matrix (Conv1D).

  • use_batch_norm – Whether to use batch normalization in the residual layers or not.

  • use_layer_norm – Whether to use layer normalization in the residual layers or not.

  • use_separable – Whether to use separabel conv1d.

  • kwargs – Any initializers for Layer class.

build(input_shape)[source]#

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(inputs, training=None)[source]#
Returns: A tuple where the first element is the residual model tensor, and the second

is the skip connection tensor.

compute_output_shape(input_shape)[source]#

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 das.tcn.tcn_new.TCN(*args, **kwargs)[source]#

Creates a TCN layer.

Input shape:

A tensor of shape (batch_size, timesteps, input_dim).

Parameters
  • nb_filters – The number of filters to use in the convolutional layers. Can be a list.

  • kernel_size – The size of the kernel to use in each convolutional layer.

  • dilations – The list of the dilations. Example is: [1, 2, 4, 8, 16, 32, 64].

  • nb_stacks – The number of stacks of residual blocks to use.

  • padding – The padding to use in the convolutional layers, ‘causal’ or ‘same’.

  • use_skip_connections – Boolean. If we want to add skip connections from input to each residual blocK.

  • return_sequences – Boolean. Whether to return the last output in the output sequence, or the full sequence.

  • activation – The activation used in the residual blocks o = Activation(x + F(x)).

  • dropout_rate – Float between 0 and 1. Fraction of the input units to drop.

  • kernel_initializer – Initializer for the kernel weights matrix (Conv1D).

  • use_batch_norm – Whether to use batch normalization in the residual layers or not.

  • use_separable – Whether to use separable convolution in the residual layers or not.

  • kwargs – Any other arguments for configuring parent class Layer. For example “name=str”, Name of the model. Use unique names when using multiple TCN.

Returns

A TCN layer.

build(input_shape)[source]#

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(inputs, training=None)[source]#

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)[source]#

Overridden in case keras uses it somewhere… no idea. Just trying to avoid future errors.

get_config()[source]#

Returns the config of a the layer. This is used for saving and loading from a model :return: python dictionary with specs to rebuild layer

das.tcn.tcn_new.channel_normalization(x: keras.engine.base_layer.Layer) keras.engine.base_layer.Layer[source]#

Normalize a layer to the maximum activation

This keeps a layers values between zero and one. It helps with relu’s unbounded activation

Parameters

x – The layer to normalize

Returns

A maximal normalized layer