ding.torch_utils.network.res_block¶
ding.torch_utils.network.res_block
¶
ResBlock
¶
Bases: Module
Overview
Residual Block with 2D convolution layers, including 3 types: basic block: input channel: C x -> 33C -> norm -> act -> 33C -> norm -> act -> out ________/+ bottleneck block: x -> 11(1/4C) -> norm -> act -> 33(1/4C) -> norm -> act -> 11C -> norm -> act -> out ____________/+ downsample block: used in EfficientZero input channel: C x -> 33C -> norm -> act -> 33C -> norm -> act -> out ___ 33C ________/+
.. note::
You can refer to Deep Residual Learning for Image Recognition <https://arxiv.org/abs/1512.03385>_ for more details.
Interfaces
__init__, forward
__init__(in_channels, activation=nn.ReLU(), norm_type='BN', res_type='basic', bias=True, out_channels=None)
¶
Overview
Init the 2D convolution residual block.
Arguments:
- in_channels (:obj:int): Number of channels in the input tensor.
- activation (:obj:nn.Module): The optional activation function.
- norm_type (:obj:str): Type of the normalization, default set to 'BN'(Batch Normalization), supports ['BN', 'LN', 'IN', 'GN', 'SyncBN', None].
- res_type (:obj:str): Type of residual block, supports ['basic', 'bottleneck', 'downsample']
- bias (:obj:bool): Whether to add a learnable bias to the conv2d_block. default set to True.
- out_channels (:obj:int): Number of channels in the output tensor, default set to None, which means out_channels = in_channels.
forward(x)
¶
Overview
Return the redisual block output.
Arguments:
- x (:obj:torch.Tensor): The input tensor.
Returns:
- x (:obj:torch.Tensor): The resblock output tensor.
ResFCBlock
¶
Bases: Module
Overview
Residual Block with 2 fully connected layers. x -> fc1 -> norm -> act -> fc2 -> norm -> act -> out _______/+
Interfaces
__init__, forward
__init__(in_channels, activation=nn.ReLU(), norm_type='BN', dropout=None)
¶
Overview
Init the fully connected layer residual block.
Arguments:
- in_channels (:obj:int): The number of channels in the input tensor.
- activation (:obj:nn.Module): The optional activation function.
- norm_type (:obj:str): The type of the normalization, default set to 'BN'.
- dropout (:obj:float): The dropout rate, default set to None.
forward(x)
¶
Overview
Return the output of the redisual block.
Arguments:
- x (:obj:torch.Tensor): The input tensor.
Returns:
- x (:obj:torch.Tensor): The resblock output tensor.
TemporalSpatialResBlock
¶
Bases: Module
Overview
Residual Block using MLP layers for both temporal and spatial input. t → time_mlp → h1 → dense2 → h2 → out ↗+ ↗+ x → dense1 → ↗ ↘ ↗ → modify_x → → → →
__init__(input_dim, output_dim, t_dim=128, activation=torch.nn.SiLU())
¶
Overview
Init the temporal spatial residual block.
Arguments:
- input_dim (:obj:int): The number of channels in the input tensor.
- output_dim (:obj:int): The number of channels in the output tensor.
- t_dim (:obj:int): The dimension of the temporal input.
- activation (:obj:nn.Module): The optional activation function.
forward(x, t)
¶
Overview
Return the redisual block output.
Arguments:
- x (:obj:torch.Tensor): The input tensor.
- t (:obj:torch.Tensor): The temporal input tensor.
Full Source Code
../ding/torch_utils/network/res_block.py