timesead.models.common.tcn ========================== .. py:module:: timesead.models.common.tcn Classes ------- .. autoapisummary:: timesead.models.common.tcn.TCNResidualBlock timesead.models.common.tcn.TCN Module Contents --------------- .. py:class:: TCNResidualBlock(input_dim: int, dilation_rate: int, nb_filters: int, kernel_size: int, padding: str, activation: Union[str, Callable] = 'relu', dropout_rate: float = 0, use_batch_norm: bool = False, use_layer_norm: bool = False) Bases: :py:obj:`torch.nn.Module` Base class for all neural network modules. Your models should also subclass this class. Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes:: import torch.nn as nn import torch.nn.functional as F class Model(nn.Module): def __init__(self) -> None: super().__init__() self.conv1 = nn.Conv2d(1, 20, 5) self.conv2 = nn.Conv2d(20, 20, 5) def forward(self, x): x = F.relu(self.conv1(x)) return F.relu(self.conv2(x)) Submodules assigned in this way will be registered, and will also have their parameters converted when you call :meth:`to`, etc. .. note:: As per the example above, an ``__init__()`` call to the parent class must be made before assignment on the child. :ivar training: Boolean represents whether this module is in training or evaluation mode. :vartype training: bool Defines the residual block for the WaveNet TCN. Input needs to be of shape (B, D, T). :param dilation_rate: The dilation power of 2 we are using for this residual block :param nb_filters: The number of convolutional filters to use in this block :param kernel_size: The size of the convolutional kernel :param padding: The padding used in the convolutional layers, 'same' or 'causal'. :param activation: The final activation used in o = Activation(x + F(x)) :param dropout_rate: Float between 0 and 1. Fraction of the input units to drop. :param use_batch_norm: Whether to use batch normalization in the residual layers or not. :param use_layer_norm: Whether to use layer normalization in the residual layers or not. .. py:attribute:: activation :value: 'relu' .. py:attribute:: dropout .. py:method:: forward(x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor] Returns: A tuple where the first element is the residual model tensor, and the second is the skip connection tensor. .. py:class:: TCN(input_dim: int, nb_filters: Union[int, Sequence[int]] = 64, kernel_size: int = 3, nb_stacks: int = 1, dilations: List[int] = (1, 2, 4, 8, 16, 32), padding: str = 'same', use_skip_connections: bool = True, dropout_rate: float = 0.0, return_sequences: bool = False, activation: Union[str, Callable] = 'relu', use_batch_norm: bool = False, use_layer_norm: bool = False) Bases: :py:obj:`torch.nn.Module` Creates a TCN layer. :param nb_filters: The number of filters to use in the convolutional layers. Can be a list. :param kernel_size: The size of the kernel to use in each convolutional layer. :param dilations: The list of the dilations. Example is: [1, 2, 4, 8, 16, 32, 64]. :param nb_stacks: The number of stacks of residual blocks to use. :param padding: The padding to use in the convolutional layers, 'causal' or 'same'. :param use_skip_connections: Boolean. If we want to add skip connections from input to each residual blocK. :param return_sequences: Boolean. Whether to return the last output in the output sequence, or the full sequence. :param activation: The activation used in the residual blocks o = Activation(x + F(x)). :param dropout_rate: Float between 0 and 1. Fraction of the input units to drop. :param use_batch_norm: Whether to use batch normalization in the residual layers or not. :param use_layer_norm: Whether to use layer normalization in the residual layers or not. :returns: A TCN layer. Initialize internal Module state, shared by both nn.Module and ScriptModule. .. py:attribute:: return_sequences :value: False .. py:attribute:: use_skip_connections :value: True .. py:attribute:: dilations :value: (1, 2, 4, 8, 16, 32) .. py:attribute:: nb_stacks :value: 1 .. py:attribute:: kernel_size :value: 3 .. py:attribute:: residual_blocks .. py:property:: receptive_field .. py:method:: forward(x: torch.Tensor) -> torch.Tensor