timesead.models.common.tcn
Classes
Base class for all neural network modules. |
|
Creates a TCN layer. |
Module Contents
- class timesead.models.common.tcn.TCNResidualBlock(input_dim: int, dilation_rate: int, nb_filters: int, kernel_size: int, padding: str, activation: str | Callable = 'relu', dropout_rate: float = 0, use_batch_norm: bool = False, use_layer_norm: bool = False)
Bases:
torch.nn.ModuleBase 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
to(), etc.Note
As per the example above, an
__init__()call to the parent class must be made before assignment on the child.- Variables:
training (bool) – Boolean represents whether this module is in training or evaluation mode.
- Parameters:
Defines the residual block for the WaveNet TCN. Input needs to be of shape (B, D, T).
- Parameters:
dilation_rate (int) – The dilation power of 2 we are using for this residual block
nb_filters (int) – The number of convolutional filters to use in this block
kernel_size (int) – The size of the convolutional kernel
padding (str) – The padding used in the convolutional layers, ‘same’ or ‘causal’.
activation (Union[str, Callable]) – The final activation used in o = Activation(x + F(x))
dropout_rate (float) – Float between 0 and 1. Fraction of the input units to drop.
use_batch_norm (bool) – Whether to use batch normalization in the residual layers or not.
use_layer_norm (bool) – Whether to use layer normalization in the residual layers or not.
input_dim (int)
- activation = 'relu'
- dropout
- 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.
- Parameters:
x (torch.Tensor)
- Return type:
Tuple[torch.Tensor, torch.Tensor]
- class timesead.models.common.tcn.TCN(input_dim: int, nb_filters: 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: str | Callable = 'relu', use_batch_norm: bool = False, use_layer_norm: bool = False)
Bases:
torch.nn.ModuleCreates a TCN layer.
- Parameters:
nb_filters (Union[int, Sequence[int]]) – The number of filters to use in the convolutional layers. Can be a list.
kernel_size (int) – The size of the kernel to use in each convolutional layer.
dilations (List[int]) – The list of the dilations. Example is: [1, 2, 4, 8, 16, 32, 64].
nb_stacks (int) – The number of stacks of residual blocks to use.
padding (str) – The padding to use in the convolutional layers, ‘causal’ or ‘same’.
use_skip_connections (bool) – Boolean. If we want to add skip connections from input to each residual blocK.
return_sequences (bool) – Boolean. Whether to return the last output in the output sequence, or the full sequence.
activation (Union[str, Callable]) – The activation used in the residual blocks o = Activation(x + F(x)).
dropout_rate (float) – Float between 0 and 1. Fraction of the input units to drop.
use_batch_norm (bool) – Whether to use batch normalization in the residual layers or not.
use_layer_norm (bool) – Whether to use layer normalization in the residual layers or not.
input_dim (int)
- Returns:
A TCN layer.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- return_sequences = False
- use_skip_connections = True
- dilations = (1, 2, 4, 8, 16, 32)
- nb_stacks = 1
- kernel_size = 3
- residual_blocks
- property receptive_field
- forward(x: torch.Tensor) torch.Tensor
- Parameters:
x (torch.Tensor)
- Return type: