espnet2.enh.layers.ncsnpp_utils.layers.CRPBlock
espnet2.enh.layers.ncsnpp_utils.layers.CRPBlock
class espnet2.enh.layers.ncsnpp_utils.layers.CRPBlock(features, n_stages, act=ReLU(), maxpool=True)
Bases: Module
Channel Reduction and Pooling Block.
This class implements a CRP (Channel Reduction and Pooling) block that applies a series of 3x3 convolutional layers followed by pooling to reduce the spatial dimensions of the input tensor while preserving its channel information. The block can be used as a building component in neural network architectures, especially in image processing tasks.
convs
List of convolutional layers to apply.
- Type: nn.ModuleList
n_stages
Number of convolutional stages.
- Type: int
pool
Pooling layer, either MaxPool or AvgPool.
- Type: nn.Module
act
Activation function applied after each convolution.
Type: callable
Parameters:
- features (int) – Number of input and output features (channels).
- n_stages (int) – Number of convolutional stages to apply.
- act (callable , optional) – Activation function to use (default: ReLU).
- maxpool (bool , optional) – If True, uses MaxPool; else uses AvgPool (default: True).
####### Examples
>>> crp_block = CRPBlock(features=64, n_stages=3)
>>> input_tensor = torch.randn(1, 64, 32, 32) # Batch size of 1
>>> output_tensor = crp_block(input_tensor)
>>> output_tensor.shape
torch.Size([1, 64, 32, 32])
NOTE
The input tensor is expected to have shape (N, C, H, W), where N is the batch size, C is the number of channels, H is the height, and W is the width of the input.
- Raises:ValueError – If features or n_stages is not positive.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
forward(x)
CRPBlock module for applying convolutional layers with pooling.
This module implements a series of convolutional layers followed by a pooling operation. The output of each convolutional layer is added to the input to form a residual connection.
convs
List of convolutional layers.
- Type: nn.ModuleList
n_stages
Number of convolutional stages.
- Type: int
pool
Pooling layer (MaxPool or AvgPool).
- Type: nn.Module
act
Activation function applied to the input.
Type: callable
Parameters:
- features (int) – Number of input and output features for the convolutions.
- n_stages (int) – Number of convolutional stages.
- act (callable , optional) – Activation function to use (default: nn.ReLU).
- maxpool (bool , optional) – If True, use MaxPool; otherwise, use AvgPool (default: True).
Returns: The output tensor after applying the convolutional layers : and pooling operations.
Return type: Tensor
####### Examples
>>> block = CRPBlock(features=64, n_stages=3)
>>> input_tensor = torch.randn(1, 64, 32, 32)
>>> output_tensor = block(input_tensor)
>>> output_tensor.shape
torch.Size([1, 64, 32, 32])
NOTE
The input tensor must have 4 dimensions (batch size, channels, height, width).