espnet2.diar.layers.tcn_nomask.TemporalBlock
espnet2.diar.layers.tcn_nomask.TemporalBlock
class espnet2.diar.layers.tcn_nomask.TemporalBlock(in_channels, out_channels, kernel_size, stride, padding, dilation, norm_type='gLN', causal=False)
Bases: Module
Temporal Block for use in Temporal Convolutional Networks (TCN).
This class implements a single block of a Temporal Convolutional Network, which consists of a 1x1 convolution, a PReLU activation, a normalization layer, and a depthwise separable convolution. The block also includes a residual connection that adds the input to the output of the block.
- Parameters:
- in_channels (int) – Number of input channels.
- out_channels (int) – Number of output channels.
- kernel_size (int) – Size of the convolutional kernel.
- stride (int) – Stride for the convolution.
- padding (int) – Padding for the convolution.
- dilation (int) – Dilation factor for the convolution.
- norm_type (str , optional) – Type of normalization to use. Can be “gLN” (global layer normalization), “cLN” (channel-wise layer normalization), or “BN” (batch normalization). Default is “gLN”.
- causal (bool , optional) – If True, the convolution is causal. Default is False.
- Returns: Output tensor of shape [M, B, K], where M is batch size, B is number of output channels, and K is sequence length.
- Return type: Tensor
Examples
>>> block = TemporalBlock(in_channels=16, out_channels=32, kernel_size=3,
... stride=1, padding=1, dilation=1)
>>> input_tensor = torch.randn(10, 16, 50) # [M, C, K]
>>> output_tensor = block(input_tensor)
>>> output_tensor.shape
torch.Size([10, 32, 50]) # Output shape
NOTE
The residual connection adds the input tensor to the output of the network. This may help in training deeper networks by alleviating the vanishing gradient problem.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
forward(x)
Forward.
- Parameters:x – [M, B, K]
- Returns: [M, B, K]