mmagic.models.editors.cain.cain_net
¶
Module Contents¶
Classes¶
CAIN network structure. |
|
Apply reflection padding, followed by a convolution, which can be |
|
Channel Attention (CA) Layer. |
|
Residual Channel Attention Module. |
|
Residual Group, consisting of a stack of residual channel attention, |
Functions¶
|
Generate padding function for CAIN. |
- class mmagic.models.editors.cain.cain_net.CAINNet(in_channels=3, kernel_size=3, num_block_groups=5, num_block_layers=12, depth=3, reduction=16, norm=None, padding=7, act=nn.LeakyReLU(0.2, True), init_cfg=None)[source]¶
Bases:
mmengine.model.BaseModule
CAIN network structure.
Paper: Channel Attention Is All You Need for Video Frame Interpolation. Ref repo: https://github.com/myungsub/CAIN
- Parameters
in_channels (int) – Channel number of inputs. Default: 3.
kernel_size (int) – Kernel size of CAINNet. Default: 3.
num_block_groups (int) – Number of block groups. Default: 5.
num_block_layers (int) – Number of blocks in a group. Default: 12.
depth (int) – Down scale depth, scale = 2**depth. Default: 3.
reduction (int) – Channel reduction of CA. Default: 16.
norm (str | None) – Normalization layer. If it is None, no normalization is performed. Default: None.
padding (int) – Padding of CAINNet. Default: 7.
act (function) – activate function. Default: nn.LeakyReLU(0.2, True).
init_cfg (dict, optional) – Initialization config dict. Default: None.
- mmagic.models.editors.cain.cain_net.get_padding_functions(x, padding=7)[source]¶
Generate padding function for CAIN.
This function produces two functions to pad and depad a tensor, given the number of pixels to be padded. When applying padding and depadding sequentially, the original tensor is obtained.
The generated padding function will pad the given tensor to the ‘padding’ power of 2, i.e., pow(2, ‘padding’).
tensor –padding_function–> padded tensor padded tensor –depadding_function–> original tensor
- Parameters
x (Tensor) – Input tensor.
padding (int) – Padding size. Default: 7.
- Returns
Padding function. depadding_function (Function): Depadding function.
- Return type
padding_function (Function)
- class mmagic.models.editors.cain.cain_net.ConvNormWithReflectionPad(in_channels, out_channels, kernel_size, norm=None)[source]¶
Bases:
mmengine.model.BaseModule
Apply reflection padding, followed by a convolution, which can be followed by an optional normalization.
- Parameters
in_channels (int) – Channel number of input features.
out_channels (int) – Channel number of output features.
kernel_size (int) – Kernel size of convolution layer.
norm (str | None) – Normalization layer. If it is None, no normalization is performed. Default: None.
- class mmagic.models.editors.cain.cain_net.ChannelAttentionLayer(mid_channels, reduction=16)[source]¶
Bases:
mmengine.model.BaseModule
Channel Attention (CA) Layer.
- Parameters
mid_channels (int) – Channel number of the intermediate features.
reduction (int) – Channel reduction of CA. Default: 16.
- class mmagic.models.editors.cain.cain_net.ResidualChannelAttention(mid_channels, kernel_size=3, reduction=16, norm=None, act=nn.LeakyReLU(0.2, True))[source]¶
Bases:
mmengine.model.BaseModule
Residual Channel Attention Module.
- Parameters
mid_channels (int) – Channel number of the intermediate features.
kernel_size (int) – Kernel size of convolution layers. Default: 3.
reduction (int) – Channel reduction. Default: 16.
norm (None | function) – Norm layer. If None, no norm layer. Default: None.
act (function) – activation function. Default: nn.LeakyReLU(0.2, True).
- class mmagic.models.editors.cain.cain_net.ResidualGroup(block_layer, num_block_layers, mid_channels, kernel_size, reduction, act=nn.LeakyReLU(0.2, True), norm=None)[source]¶
Bases:
mmengine.model.BaseModule
Residual Group, consisting of a stack of residual channel attention, followed by a convolution.
- Parameters
block_layer (nn.Module) – nn.Module class for basic block.
num_block_layers (int) – number of blocks.
mid_channels (int) – Channel number of the intermediate features.
kernel_size (int) – Kernel size of ResidualGroup.
reduction (int) – Channel reduction of CA. Default: 16.
act (function) – activation function. Default: nn.LeakyReLU(0.2, True).
norm (str | None) – Normalization layer. If it is None, no normalization is performed. Default: None.