Shortcuts

mmagic.models.editors.singan.singan_modules

Module Contents

Classes

GeneratorBlock

Generator block used in SinGAN.

DiscriminatorBlock

Discriminator Block used in SinGAN.

class mmagic.models.editors.singan.singan_modules.GeneratorBlock(in_channels, out_channels, kernel_size, padding, num_layers, base_channels, min_feat_channels, out_act_cfg=dict(type='Tanh'), stride=1, allow_no_residual=False, **kwargs)[source]

Bases: torch.nn.Module

Generator block used in SinGAN.

Parameters
  • in_channels (int) – Input channels.

  • out_channels (int) – Output channels.

  • num_scales (int) – The number of scales/stages in generator. Note that this number is counted from zero, which is the same as the original paper.

  • kernel_size (int, optional) – Kernel size, same as nn.Conv2d. Defaults to 3.

  • padding (int, optional) – Padding for the convolutional layer, same as nn.Conv2d. Defaults to 0.

  • num_layers (int, optional) – The number of convolutional layers in each generator block. Defaults to 5.

  • base_channels (int, optional) – The basic channels for convolutional layers in the generator block. Defaults to 32.

  • min_feat_channels (int, optional) – Minimum channels for the feature maps in the generator block. Defaults to 32.

  • out_act_cfg (dict | None, optional) – Configs for output activation layer. Defaults to dict(type=’Tanh’).

  • stride (int, optional) – Same as nn.Conv2d. Defaults to 1.

  • allow_no_residual (bool, optional) – Whether to allow no residual link in this block. Defaults to False.

forward(x, prev)[source]

Forward function.

Parameters
  • x (Tensor) – Input feature map.

  • prev (Tensor) – Previous feature map.

Returns

Output feature map with the shape of (N, C, H, W).

Return type

Tensor

init_weights(pretrained=None)[source]
class mmagic.models.editors.singan.singan_modules.DiscriminatorBlock(in_channels, base_channels, min_feat_channels, kernel_size, padding, num_layers, norm_cfg=dict(type='BN'), act_cfg=dict(type='LeakyReLU', negative_slope=0.2), stride=1, **kwargs)[source]

Bases: torch.nn.Module

Discriminator Block used in SinGAN.

Parameters
  • in_channels (int) – Input channels.

  • base_channels (int) – Base channels for this block.

  • min_feat_channels (int) – The minimum channels for feature map.

  • kernel_size (int) – Size of convolutional kernel, same as nn.Conv2d.

  • padding (int) – Padding for convolutional layer, same as nn.Conv2d.

  • num_layers (int) – The number of convolutional layers in this block.

  • norm_cfg (dict | None, optional) – Config for the normalization layer. Defaults to dict(type=’BN’).

  • act_cfg (dict | None, optional) – Config for the activation layer. Defaults to dict(type=’LeakyReLU’, negative_slope=0.2).

  • stride (int, optional) – The stride for the convolutional layer, same as nn.Conv2d. Defaults to 1.

forward(x)[source]

Forward function.

Parameters

x (Tensor) – Input feature map with shape of (N, C, H, W).

Returns

Output feature map.

Return type

Tensor

init_weights(pretrained=None)[source]
Read the Docs v: latest
Versions
latest
stable
0.x
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.