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.

This is typically used to create the weights of Layer subclasses.

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.

If the layer has not been built, this method will call build on the layer. This assumes 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.

This is typically used to create the weights of Layer subclasses.

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.

Note here that call() method in tf.keras is little bit different from keras API. In keras API, you can pass support masking for layers as additional arguments. Whereas tf.keras has compute_mask() method to support masking.

Parameters
  • inputs – Input tensor, or list/tuple of input tensors.

  • *args – Additional positional arguments. Currently unused.

  • **kwargs – Additional keyword arguments. Currently unused.

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: tensorflow.python.keras.engine.base_layer.Layer) tensorflow.python.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