espnet2.enh.layers.ncsnpp_utils.layers.UpsampleConv
espnet2.enh.layers.ncsnpp_utils.layers.UpsampleConv
class espnet2.enh.layers.ncsnpp_utils.layers.UpsampleConv(input_dim, output_dim, kernel_size=3, biases=True)
Bases: Module
Upsampling convolution layer.
This layer performs upsampling on the input tensor using PixelShuffle after concatenating the input with itself four times. The upsampled output is then passed through a convolutional layer.
conv
The convolutional layer that processes the output after upsampling.
- Type: nn.Conv2d
pixelshuffle
The layer that performs pixel shuffling to upscale the input.
Type: nn.PixelShuffle
Parameters:
- input_dim (int) – Number of input channels.
- output_dim (int) – Number of output channels.
- kernel_size (int , optional) – Size of the convolving kernel. Default is 3.
- biases (bool , optional) – If True, adds a learnable bias to the output. Default is True.
Returns: The output tensor after upsampling and convolution.
Return type: Tensor
####### Examples
>>> upsample_conv = UpsampleConv(input_dim=16, output_dim=32)
>>> input_tensor = torch.randn(1, 16, 64, 64)
>>> output_tensor = upsample_conv(input_tensor)
>>> output_tensor.shape
torch.Size([1, 32, 128, 128])
NOTE
The input tensor is expected to have 4 dimensions: (batch_size, channels, height, width). The output tensor will have its height and width doubled.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
forward(inputs)
Forward pass through the Conditional Residual Block.
This method applies a series of normalization, activation, and convolutional operations to the input tensor x. It also incorporates a conditional input y for normalization purposes, allowing the block to learn class-specific features.
- Parameters:
- x (torch.Tensor) – Input tensor of shape (B, C, H, W), where B is the batch size, C is the number of input channels, H is the height, and W is the width of the input.
- y (torch.Tensor) – Conditional input tensor of shape (B, num_classes) used for normalization.
- Returns: Output tensor of the same shape as input x, : after applying the operations defined in the block.
- Return type: torch.Tensor
NOTE
The behavior of the block depends on the resample attribute:
- If resample is “down”, the spatial dimensions of the output
are reduced.
- If resample is None, the input dimensions remain unchanged.
- If the output dimensions differ from the input dimensions, a shortcut connection is applied to match the dimensions.
####### Examples
>>> block = ConditionalResidualBlock(input_dim=64, output_dim=128,
... num_classes=10)
>>> x = torch.randn(8, 64, 32, 32) # Batch of 8, 64 channels, 32x32
>>> y = torch.randint(0, 10, (8,)) # Random class labels for 8 samples
>>> output = block(x, y)
>>> output.shape
torch.Size([8, 128, 32, 32]) # Output shape will be (B, output_dim, H, W)