espnet2.gan_codec.shared.decoder.seanet.NormConvTranspose1d
espnet2.gan_codec.shared.decoder.seanet.NormConvTranspose1d
class espnet2.gan_codec.shared.decoder.seanet.NormConvTranspose1d(*args, causal: bool = False, norm: str = 'none', norm_kwargs: Dict[str, Any] = {}, **kwargs)
Bases: Module
Wrapper around ConvTranspose1d with normalization for uniformity.
This class encapsulates the functionality of a 1D transposed convolution (also known as a deconvolution) and applies a normalization technique to ensure consistency across various normalization approaches.
convtr
The transposed convolution layer.
- Type: nn.Module
norm
The normalization layer applied to the transposed convolution output.
- Type: nn.Module
norm
The type of normalization used.
Type: str
Parameters:
- *args – Variable length argument list for the transposed convolution.
- causal (bool) – If True, the convolution is causal (i.e., it only considers past inputs). Defaults to False.
- norm (str) – The normalization method to apply. Defaults to “none”.
- norm_kwargs (Dict *[*str , Any ]) – Additional keyword arguments for the normalization layer.
- **kwargs – Additional keyword arguments for the transposed convolution.
####### Examples
>>> layer = NormConvTranspose1d(in_channels=16, out_channels=33,
... kernel_size=3, stride=2, norm='batch_norm')
>>> input_tensor = torch.randn(1, 16, 50)
>>> output_tensor = layer(input_tensor)
>>> output_tensor.shape
torch.Size([1, 33, 98])
- Raises:ValueError – If any of the arguments passed to the convolution layer are invalid.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
forward(x)
Applies the transposed convolution followed by normalization to the input.
- Parameters:x (torch.Tensor) – The input tensor to the transposed convolution. It is expected to have shape (batch_size, in_channels, length).
- Returns: The output tensor after applying the transposed convolution and normalization. The shape of the output will depend on the parameters of the convolution.
- Return type: torch.Tensor
####### Examples
>>> model = NormConvTranspose1d(in_channels=16, out_channels=32,
... kernel_size=3, stride=2)
>>> input_tensor = torch.randn(8, 16, 10) # batch_size=8, in_channels=16
>>> output_tensor = model(input_tensor)
>>> output_tensor.shape
torch.Size([8, 32, 20]) # Output shape after transposed convolution
NOTE
The normalization method applied can be specified during the initialization of the class. This method can handle various normalization techniques seamlessly, providing a uniform interface for different approaches.
- Raises:ValueError – If the input tensor does not have the expected shape.