espnet2.enh.layers.ncsnpp_utils.layers.RefineBlock
espnet2.enh.layers.ncsnpp_utils.layers.RefineBlock
class espnet2.enh.layers.ncsnpp_utils.layers.RefineBlock(in_planes, features, act=ReLU(), start=False, end=False, maxpool=True)
Bases: Module
Refinement block for feature extraction and processing.
This block is designed to adaptively refine features from multiple input sources using Residual Convolutional Units (RCU), a Multi-Scale Feature (MSF) block, and a Conditional Residual Processing (CRP) block. It allows for the combination of features from different resolutions and enhances them through a series of convolutions.
adapt_convs
List of RCU blocks for adapting input features.
- Type: nn.ModuleList
output_convs
RCU block for generating output features.
- Type:RCUBlock
msf
Multi-Scale Feature block for combining features.
- Type:MSFBlock
crp
Conditional Residual Processing block for refining features.
Type:CRPBlock
Parameters:
- in_planes (tuple or list) – Number of input feature planes for each block.
- features (int) – Number of output feature planes for the final output.
- act (callable) – Activation function to use (default: ReLU).
- start (bool) – Flag indicating if this block is the starting block (default: False).
- end (bool) – Flag indicating if this block is the ending block (default: False).
- maxpool (bool) – Flag indicating if max pooling should be used (default: True).
Raises:AssertionError – If in_planes is not a tuple or list.
####### Examples
>>> refine_block = RefineBlock((64, 128), 256)
>>> output = refine_block((input_tensor1, input_tensor2), output_shape)
NOTE
The start and end flags can be used to customize the behavior of the block based on its position in the overall network architecture.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
forward(xs, output_shape)
RefineBlock for hierarchical feature refinement in deep networks.
This module refines input features from multiple sources through a series of convolutional layers, pooling operations, and residual connections. It is designed to adaptively fuse features from various input resolutions, enhancing the network’s ability to capture complex patterns.
n_blocks
Number of input feature blocks.
- Type: int
adapt_convs
List of Residual Convolutional Units (RCUs) for adapting input features.
- Type: nn.ModuleList
output_convs
RCU for producing output features.
- Type:RCUBlock
msf
Multi-scale feature fusion block, if applicable.
- Type:MSFBlock
crp
Contextual Refinement Pooling block.
Type:CRPBlock
Parameters:
- in_planes (list or tuple) – A list or tuple of input feature dimensions.
- features (int) – Number of output features for the final layer.
- act (callable) – Activation function to use (default: nn.ReLU).
- start (bool) – Whether this block is at the start of the network (default: False).
- end (bool) – Whether this block is at the end of the network (default: False).
- maxpool (bool) – Whether to use max pooling in CRPBlock (default: True).
####### Examples
>>> refine_block = RefineBlock(in_planes=(64, 128), features=256)
>>> input_features = (torch.randn(1, 64, 32, 32), torch.randn(1, 128, 16, 16))
>>> output = refine_block(input_features, output_shape=(16, 16))
>>> print(output.shape)
torch.Size([1, 256, 16, 16])