espnet2.diar.layers.tcn_nomask.chose_norm
Less than 1 minute
espnet2.diar.layers.tcn_nomask.chose_norm
espnet2.diar.layers.tcn_nomask.chose_norm(norm_type, channel_size)
Choose the appropriate normalization layer based on the given type.
The input of normalization will be (M, C, K), where M is the batch size, C is the channel size, and K is the sequence length. The function supports different types of normalization: global layer normalization (gLN), channel-wise layer normalization (cLN), and batch normalization (BN).
- Parameters:
- norm_type (str) – The type of normalization to use. Should be one of: “gLN” for Global Layer Normalization, “cLN” for Channel-wise Layer Normalization, “BN” for Batch Normalization.
- channel_size (int) – The number of channels for normalization.
- Returns: The corresponding normalization layer.
- Return type: nn.Module
- Raises:ValueError – If the norm_type is not one of the supported types.
Examples
>>> norm_layer = chose_norm("gLN", 64)
>>> output = norm_layer(torch.randn(10, 64, 100))
>>> norm_layer = chose_norm("cLN", 32)
>>> output = norm_layer(torch.randn(10, 32, 100))
>>> norm_layer = chose_norm("BN", 128)
>>> output = norm_layer(torch.randn(10, 128, 100))
NOTE
This function is designed to provide a flexible way to select normalization methods in the context of temporal convolutional networks.