espnet2.gan_codec.hificodec.module.ResBlock2
espnet2.gan_codec.hificodec.module.ResBlock2
class espnet2.gan_codec.hificodec.module.ResBlock2(channels, kernel_size=3, dilation=(1, 3))
Bases: Module
Residual Block with two convolutional layers and leaky ReLU activation.
This class implements a residual block consisting of two convolutional layers, each followed by a leaky ReLU activation function. The input to the block is added to the output of the second convolutional layer to form the residual connection.
convs
A list containing the convolutional layers with weight normalization applied.
Type: nn.ModuleList
Parameters:
- channels (int) – The number of input and output channels for the convolutional layers.
- kernel_size (int , optional) – The size of the convolutional kernel. Default is 3.
- dilation (tuple , optional) – The dilation rates for the convolutional layers. Default is (1, 3).
######### Examples
>>> res_block = ResBlock2(channels=64, kernel_size=3, dilation=(1, 3))
>>> input_tensor = torch.randn(1, 64, 128) # (batch_size, channels, length)
>>> output_tensor = res_block(input_tensor)
>>> output_tensor.shape
torch.Size([1, 64, 128])
NOTE
The leaky ReLU uses a negative slope defined by the constant LRELU_SLOPE.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
forward(x)
Forward pass for the generator network.
This method takes an input tensor x, applies a series of convolutional and transposed convolutional layers along with residual blocks to produce the output. The output is a processed tensor that has gone through upsampling and activation functions.
- Parameters:x (torch.Tensor) – Input tensor of shape (B, C, T) where: B = batch size, C = number of channels, T = length of the sequence.
- Returns: Output tensor of shape (B, 1, T’) where T’ is the length of the output sequence after processing.
- Return type: torch.Tensor
######### Examples
>>> generator = Generator(...)
>>> input_tensor = torch.randn(8, 256, 100) # Example input
>>> output_tensor = generator(input_tensor)
>>> print(output_tensor.shape)
torch.Size([8, 1, T']) # Output shape will vary depending on
# the generator configuration.
remove_weight_norm()
Remove weight normalization from the model layers.
This method removes weight normalization from all the layers in the Generator or Encoder model, including upsampling layers, residual blocks, and the convolutional layers at the beginning and end. It is typically used before saving the model or during the evaluation phase to ensure that the model behaves as expected.
NOTE
Weight normalization is a technique that can help in training deep networks by reparameterizing the weight vectors. However, for inference or model deployment, it may be necessary to remove this normalization.
######### Examples
>>> generator = Generator(...)
>>> generator.remove_weight_norm()
- Raises:
- RuntimeError – If the layers do not have weight normalization
- applied. –