espnet2.enh.layers.ncsnpp_utils.normalization.NoneNorm2d
espnet2.enh.layers.ncsnpp_utils.normalization.NoneNorm2d
class espnet2.enh.layers.ncsnpp_utils.normalization.NoneNorm2d(num_features, bias=True)
Bases: Module
A normalization layer that performs no normalization.
This class implements a no-operation (identity) normalization layer for 2D inputs. It can be used as a placeholder in architectures where normalization is required but should be skipped.
num_features
The number of input features (channels).
- Type: int
bias
Whether to use bias in the layer. This is not used in this implementation.
Type: bool
Parameters:
- num_features (int) – The number of input features (channels).
- bias (bool) – A flag to indicate if bias should be used (default: True).
Returns: The input tensor x is returned unchanged.
Return type: Tensor
####### Examples
>>> import torch
>>> layer = NoneNorm2d(num_features=64)
>>> input_tensor = torch.randn(1, 64, 32, 32) # Batch size of 1
>>> output_tensor = layer(input_tensor)
>>> print(output_tensor.shape)
torch.Size([1, 64, 32, 32]) # Output shape is the same as input shape
NOTE
This layer is primarily used in models where normalization is optional.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
forward(x)
Applies the normalization transformation to the input tensor.
This method takes an input tensor x and a condition tensor y to perform normalization. The specific type of normalization applied depends on the initialization of the instance. If bias is enabled, the output will be adjusted with learned scaling (gamma) and shifting (beta) parameters derived from the embedding of y.
- Parameters:
- x (torch.Tensor) – The input tensor of shape (N, C, H, W), where N is the batch size, C is the number of channels, and H and W are the height and width of the input feature maps.
- y (torch.Tensor) – The condition tensor of shape (N,) that contains class indices for the embedding layer. The indices must be in the range [0, num_classes).
- Returns: The output tensor after applying the normalization operation, with the same shape as the input tensor x.
- Return type: torch.Tensor
####### Examples
>>> model = ConditionalInstanceNorm2d(num_features=64, num_classes=10)
>>> x = torch.randn(8, 64, 32, 32) # Batch of 8 images
>>> y = torch.randint(0, 10, (8,)) # Random class indices
>>> output = model(x, y)
>>> print(output.shape)
torch.Size([8, 64, 32, 32])
NOTE
The output may differ depending on the values of x and y, as well as the learned parameters from the embedding layer.
- Raises:
- RuntimeError – If the input tensor x and condition tensor y
- have incompatible shapes or if any of the operations within –
- the method fail. –