Shortcuts

mmedit.models.editors.gca.resgca_dec

Module Contents

Classes

BasicBlockDec

Basic residual block for decoder.

ResNetDec

ResNet decoder for image matting.

ResShortcutDec

ResNet decoder for image matting with shortcut connection.

ResGCADecoder

ResNet decoder with shortcut connection and gca module.

class mmedit.models.editors.gca.resgca_dec.BasicBlockDec(in_channels, out_channels, kernel_size=3, stride=1, interpolation=None, conv_cfg=None, norm_cfg=dict(type='BN'), act_cfg=dict(type='ReLU'), with_spectral_norm=False)[source]

Bases: mmedit.models.editors.gca.resgca_enc.BasicBlock

Basic residual block for decoder.

For decoder, we use ConvTranspose2d with kernel_size 4 and padding 1 for conv1. And the output channel of conv1 is modified from out_channels to in_channels.

build_conv1(in_channels, out_channels, kernel_size, stride, conv_cfg, norm_cfg, act_cfg, with_spectral_norm)[source]

Build conv1 of the block.

Parameters
  • in_channels (int) – The input channels of the ConvModule.

  • out_channels (int) – The output channels of the ConvModule.

  • kernel_size (int) – The kernel size of the ConvModule.

  • stride (int) – The stride of the ConvModule. If stride is set to 2, then conv_cfg will be overwritten as dict(type='Deconv') and kernel_size will be overwritten as 4.

  • conv_cfg (dict) – The conv config of the ConvModule.

  • norm_cfg (dict) – The norm config of the ConvModule.

  • act_cfg (dict) – The activation config of the ConvModule.

  • with_spectral_norm (bool) – Whether use spectral norm.

Returns

The built ConvModule.

Return type

nn.Module

build_conv2(in_channels, out_channels, kernel_size, conv_cfg, norm_cfg, with_spectral_norm)[source]

Build conv2 of the block.

Parameters
  • in_channels (int) – The input channels of the ConvModule.

  • out_channels (int) – The output channels of the ConvModule.

  • kernel_size (int) – The kernel size of the ConvModule.

  • conv_cfg (dict) – The conv config of the ConvModule.

  • norm_cfg (dict) – The norm config of the ConvModule.

  • with_spectral_norm (bool) – Whether use spectral norm.

Returns

The built ConvModule.

Return type

nn.Module

class mmedit.models.editors.gca.resgca_dec.ResNetDec(block, layers, in_channels, kernel_size=3, conv_cfg=None, norm_cfg=dict(type='BN'), act_cfg=dict(type='LeakyReLU', negative_slope=0.2, inplace=True), with_spectral_norm=False, late_downsample=False, init_cfg: Optional[dict] = None)[source]

Bases: mmengine.model.BaseModule

ResNet decoder for image matting.

This class is adopted from https://github.com/Yaoyi-Li/GCA-Matting.

Parameters
  • block (str) – Type of residual block. Currently only BasicBlockDec is implemented.

  • layers (list[int]) – Number of layers in each block.

  • in_channels (int) – Channel num of input features.

  • kernel_size (int) – Kernel size of the conv layers in the decoder.

  • conv_cfg (dict) – dictionary to construct convolution layer. If it is None, 2d convolution will be applied. Default: None.

  • norm_cfg (dict) – Config dict for normalization layer. “BN” by default.

  • act_cfg (dict) – Config dict for activation layer, “ReLU” by default.

  • with_spectral_norm (bool) – Whether use spectral norm after conv. Default: False.

  • late_downsample (bool) – Whether to adopt late downsample strategy, Default: False.

  • init_cfg (dict, optional) – Initialization config dict. Default: None.

init_weights()[source]

Init weights for the module.

_make_layer(block, planes, num_blocks, conv_cfg, norm_cfg, act_cfg, with_spectral_norm)[source]
forward(x)[source]

Forward function.

Parameters

x (Tensor) – Input tensor with shape (N, C, H, W).

Returns

Output tensor.

Return type

Tensor

class mmedit.models.editors.gca.resgca_dec.ResShortcutDec(block, layers, in_channels, kernel_size=3, conv_cfg=None, norm_cfg=dict(type='BN'), act_cfg=dict(type='LeakyReLU', negative_slope=0.2, inplace=True), with_spectral_norm=False, late_downsample=False, init_cfg: Optional[dict] = None)[source]

Bases: ResNetDec

ResNet decoder for image matting with shortcut connection.

feat1 --------------------------- conv2 --- out
                               |
feat2 ---------------------- conv1
                          |
feat3 ----------------- layer4
                     |
feat4 ------------ layer3
                |
feat5 ------- layer2
           |
out ---  layer1
Parameters
  • block (str) – Type of residual block. Currently only BasicBlockDec is implemented.

  • layers (list[int]) – Number of layers in each block.

  • in_channels (int) – Channel number of input features.

  • kernel_size (int) – Kernel size of the conv layers in the decoder.

  • conv_cfg (dict) – Dictionary to construct convolution layer. If it is None, 2d convolution will be applied. Default: None.

  • norm_cfg (dict) – Config dict for normalization layer. “BN” by default.

  • act_cfg (dict) – Config dict for activation layer, “ReLU” by default.

  • late_downsample (bool) – Whether to adopt late downsample strategy, Default: False.

forward(inputs)[source]

Forward function of resnet shortcut decoder.

Parameters

inputs (dict) –

Output dictionary of the ResNetEnc containing:

  • out (Tensor): Output of the ResNetEnc.

  • feat1 (Tensor): Shortcut connection from input image.

  • feat2 (Tensor): Shortcut connection from conv2 of ResNetEnc.

  • feat3 (Tensor): Shortcut connection from layer1 of ResNetEnc.

  • feat4 (Tensor): Shortcut connection from layer2 of ResNetEnc.

  • feat5 (Tensor): Shortcut connection from layer3 of ResNetEnc.

Returns

Output tensor.

Return type

Tensor

class mmedit.models.editors.gca.resgca_dec.ResGCADecoder(block, layers, in_channels, kernel_size=3, conv_cfg=None, norm_cfg=dict(type='BN'), act_cfg=dict(type='LeakyReLU', negative_slope=0.2, inplace=True), with_spectral_norm=False, late_downsample=False)[source]

Bases: ResShortcutDec

ResNet decoder with shortcut connection and gca module.

feat1 ---------------------------------------- conv2 --- out
                                            |
feat2 ----------------------------------- conv1
                                       |
feat3 ------------------------------ layer4
                                  |
feat4, img_feat -- gca_module - layer3
                |
feat5 ------- layer2
           |
out ---  layer1
  • gca module also requires unknown tensor generated by trimap which is ignored in the above graph.

Parameters
  • block (str) – Type of residual block. Currently only BasicBlockDec is implemented.

  • layers (list[int]) – Number of layers in each block.

  • in_channels (int) – Channel number of input features.

  • kernel_size (int) – Kernel size of the conv layers in the decoder.

  • conv_cfg (dict) – Dictionary to construct convolution layer. If it is None, 2d convolution will be applied. Default: None.

  • norm_cfg (dict) – Config dict for normalization layer. “BN” by default.

  • act_cfg (dict) – Config dict for activation layer, “ReLU” by default.

  • with_spectral_norm (bool) – Whether use spectral norm. Default: False.

  • late_downsample (bool) – Whether to adopt late downsample strategy, Default: False.

forward(inputs)[source]

Forward function of resnet shortcut decoder.

Parameters

inputs (dict) –

Output dictionary of the ResGCAEncoder containing:

  • out (Tensor): Output of the ResGCAEncoder.

  • feat1 (Tensor): Shortcut connection from input image.

  • feat2 (Tensor): Shortcut connection from conv2 of ResGCAEncoder.

  • feat3 (Tensor): Shortcut connection from layer1 of ResGCAEncoder.

  • feat4 (Tensor): Shortcut connection from layer2 of ResGCAEncoder.

  • feat5 (Tensor): Shortcut connection from layer3 of ResGCAEncoder.

  • img_feat (Tensor): Image feature extracted by guidance head.

  • unknown (Tensor): Unknown tensor generated by trimap.

Returns

Output tensor.

Return type

Tensor

Read the Docs v: latest
Versions
master
latest
stable
zyh-re-docs
zyh-doc-notfound-extend
zyh-api-rendering
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.