espnet2.enh.layers.dc_crn.DenselyConnectedBlock
espnet2.enh.layers.dc_crn.DenselyConnectedBlock
class espnet2.enh.layers.dc_crn.DenselyConnectedBlock(in_channels, out_channels, hid_channels=8, kernel_size=(1, 3), padding=(0, 1), last_kernel_size=(1, 4), last_stride=(1, 2), last_padding=(0, 1), last_output_padding=(0, 0), layers=5, transposed=False)
Bases: Module
Densely-Connected Convolutional Block.
This module implements a densely-connected convolutional block, where each layer receives input from all previous layers, enabling feature reuse and improving gradient flow.
Args: : in_channels (int): Number of input channels. out_channels (int): Number of output channels. hid_channels (int): Number of output channels in intermediate <br/>
convolutional layers. <br/> kernel_size (tuple): Kernel size for all but the last convolutional : layers. <br/> padding (tuple): Padding for all but the last convolutional layers. last_kernel_size (tuple): Kernel size for the last GluConv layer. last_stride (tuple): Stride for the last GluConv layer. last_padding (tuple): Padding for the last GluConv layer. last_output_padding (tuple): Output padding for the last <br/> GluConvTranspose2d (only used when transposed=True). <br/> layers (int): Total number of convolutional layers. transposed (bool): True to use GluConvTranspose2d in the last layer, <br/> False to use GluConv2d in the last layer.
Raises: : AssertionError: If layers is less than or equal to 1.
Densely-Connected Convolutional Block.
- Parameters:
- in_channels (int) – number of input channels
- out_channels (int) – number of output channels
- hid_channels (int) – number of output channels in intermediate Conv layers
- kernel_size (tuple) – kernel size for all but the last Conv layers
- padding (tuple) – padding for all but the last Conv layers
- last_kernel_size (tuple) – kernel size for the last GluConv layer
- last_stride (tuple) – stride for the last GluConv layer
- last_padding (tuple) – padding for the last GluConv layer
- last_output_padding (tuple) – output padding for the last GluConvTranspose2d (only used when transposed=True)
- layers (int) – total number of Conv layers
- transposed (bool) – True to use GluConvTranspose2d in the last layer False to use GluConv2d in the last layer
forward(input)
DenselyConnectedBlock forward.
This method computes the forward pass of the Densely Connected Block, which applies a series of convolutional layers and concatenates the outputs of previous layers to enable dense connections.
- Parameters:input (torch.Tensor) – Input tensor of shape (B, C, T_in, F_in), where B is the batch size, C is the number of channels, T_in is the input time dimension, and F_in is the input frequency dimension.
- Returns: Output tensor of shape (B, C, T_out, F_out), : where T_out is the output time dimension and F_out is the output frequency dimension.
- Return type: out (torch.Tensor)
Examples
>>> import torch
>>> block = DenselyConnectedBlock(2, 4)
>>> input_tensor = torch.randn(1, 2, 42, 127)
>>> output_tensor = block(input_tensor)
>>> print(output_tensor.shape)
torch.Size([1, 4, 42, 127])
NOTE
The output size depends on the parameters defined during the initialization of the DenselyConnectedBlock and the concatenation of outputs from previous layers.