Shortcuts

mmedit.models.editors.sagan.sagan_modules

Module Contents

Classes

SNGANGenResBlock

ResBlock used in Generator of SNGAN / Proj-GAN.

SNGANDiscResBlock

resblock used in discriminator of sngan / proj-gan.

SNGANDiscHeadResBlock

The first ResBlock used in discriminator of sngan / proj-gan. Compared

SNConditionNorm

Conditional Normalization for SNGAN / Proj-GAN. The implementation

class mmedit.models.editors.sagan.sagan_modules.SNGANGenResBlock(in_channels, out_channels, hidden_channels=None, num_classes=0, use_cbn=True, use_norm_affine=False, act_cfg=dict(type='ReLU'), norm_cfg=dict(type='BN'), upsample_cfg=dict(type='nearest', scale_factor=2), upsample=True, auto_sync_bn=True, conv_cfg=None, with_spectral_norm=False, with_embedding_spectral_norm=None, sn_style='torch', norm_eps=0.0001, sn_eps=1e-12, init_cfg=dict(type='BigGAN'))[源代码]

Bases: torch.nn.Module

ResBlock used in Generator of SNGAN / Proj-GAN.

参数
  • in_channels (int) – Input channels.

  • out_channels (int) – Output channels.

  • hidden_channels (int, optional) – Input channels of the second Conv layer of the block. If None is given, would be set as out_channels. Default to None.

  • num_classes (int, optional) – Number of classes would like to generate. This argument would pass to norm layers and influence the structure and behavior of the normalization process. Default to 0.

  • use_cbn (bool, optional) – Whether use conditional normalization. This argument would pass to norm layers. Default to True.

  • use_norm_affine (bool, optional) – Whether use learnable affine parameters in norm operation when cbn is off. Default False.

  • act_cfg (dict, optional) – Config for activate function. Default to dict(type='ReLU').

  • upsample_cfg (dict, optional) – Config for the upsample method. Default to dict(type='nearest', scale_factor=2).

  • upsample (bool, optional) – Whether apply upsample operation in this module. Default to True.

  • auto_sync_bn (bool, optional) – Whether convert Batch Norm to Synchronized ones when Distributed training is on. Default to True.

  • conv_cfg (dict | None) – Config for conv blocks of this module. If pass None, would use _default_conv_cfg. Default to None.

  • with_spectral_norm (bool, optional) – Whether use spectral norm for conv blocks and norm layers. Default to True.

  • with_embedding_spectral_norm (bool, optional) – Whether use spectral norm for embedding layers in normalization blocks or not. If not specified (set as None), with_embedding_spectral_norm would be set as the same value as with_spectral_norm. Default to None.

  • sn_style (str, optional) – The style of spectral normalization. If set to ajbrock, implementation by ajbrock(https://github.com/ajbrock/BigGAN-PyTorch/blob/master/layers.py) will be adopted. If set to torch, implementation by PyTorch will be adopted. Defaults to torch.

  • norm_eps (float, optional) – eps for Normalization layers (both conditional and non-conditional ones). Default to 1e-4.

  • sn_eps (float, optional) – eps for spectral normalization operation. Default to 1e-12.

  • init_cfg (dict, optional) – Config for weight initialization. Default to dict(type='BigGAN').

_default_conv_cfg[源代码]
forward(x, y=None)[源代码]

Forward function.

参数
  • x (Tensor) – Input tensor with shape (n, c, h, w).

  • y (Tensor) – Input label with shape (n, ). Default None.

返回

Forward results.

返回类型

Tensor

forward_shortcut(x)[源代码]

Forward the shortcut branch.

参数

x (Tensor) – Input tensor with shape (n, c, h, w).

返回

Forward results.

返回类型

Tensor

init_weights()[源代码]

Initialize weights for the model.

class mmedit.models.editors.sagan.sagan_modules.SNGANDiscResBlock(in_channels, out_channels, hidden_channels=None, downsample=False, act_cfg=dict(type='ReLU'), conv_cfg=None, with_spectral_norm=True, sn_style='torch', sn_eps=1e-12, init_cfg=dict(type='BigGAN'))[源代码]

Bases: torch.nn.Module

resblock used in discriminator of sngan / proj-gan.

参数
  • in_channels (int) – input channels.

  • out_channels (int) – output channels.

  • hidden_channels (int, optional) – input channels of the second conv layer of the block. if none is given, would be set as out_channels. Defaults to none.

  • downsample (bool, optional) – whether apply downsample operation in this module. Defaults to false.

  • act_cfg (dict, optional) – config for activate function. default to dict(type='relu').

  • conv_cfg (dict | none) – config for conv blocks of this module. if pass none, would use _default_conv_cfg. default to none.

  • with_spectral_norm (bool, optional) – whether use spectral norm for conv blocks and norm layers. Defaults to true.

  • sn_eps (float, optional) – eps for spectral normalization operation. Default to 1e-12.

  • sn_style (str, optional) – The style of spectral normalization. If set to ajbrock, implementation by ajbrock(https://github.com/ajbrock/BigGAN-PyTorch/blob/master/layers.py) will be adopted. If set to torch, implementation by PyTorch will be adopted. Defaults to torch.

  • init_cfg (dict, optional) – Config for weight initialization. Defaults to dict(type='BigGAN').

_default_conv_cfg[源代码]
forward(x)[源代码]

Forward function.

参数

x (Tensor) – Input tensor with shape (n, c, h, w).

返回

Forward results.

返回类型

Tensor

forward_shortcut(x: torch.Tensor) torch.Tensor[源代码]

Forward the shortcut branch.

参数

x (Tensor) – Input tensor with shape (n, c, h, w).

返回

Forward results.

返回类型

Tensor

init_weights()[源代码]

Initialize weights.

class mmedit.models.editors.sagan.sagan_modules.SNGANDiscHeadResBlock(in_channels, out_channels, conv_cfg=None, act_cfg=dict(type='ReLU'), with_spectral_norm=True, sn_eps=1e-12, sn_style='torch', init_cfg=dict(type='BigGAN'))[源代码]

Bases: torch.nn.Module

The first ResBlock used in discriminator of sngan / proj-gan. Compared to SNGANDisResBlock, this module has a different forward order.

参数
  • in_channels (int) – Input channels.

  • out_channels (int) – Output channels.

  • downsample (bool, optional) – whether apply downsample operation in this module. default to false.

  • conv_cfg (dict | none) – config for conv blocks of this module. if pass none, would use _default_conv_cfg. default to none.

  • act_cfg (dict, optional) – config for activate function. default to dict(type='relu').

  • with_spectral_norm (bool, optional) – whether use spectral norm for conv blocks and norm layers. default to true.

  • sn_style (str, optional) – The style of spectral normalization. If set to ajbrock, implementation by ajbrock(https://github.com/ajbrock/BigGAN-PyTorch/blob/master/layers.py) will be adopted. If set to torch, implementation by PyTorch will be adopted. Defaults to torch.

  • sn_eps (float, optional) – eps for spectral normalization operation. Default to 1e-12.

  • init_cfg (dict, optional) – Config for weight initialization. Default to dict(type='BigGAN').

_default_conv_cfg[源代码]
forward(x: torch.Tensor) torch.Tensor[源代码]

Forward function.

参数

x (Tensor) – Input tensor with shape (n, c, h, w).

返回

Forward results.

返回类型

Tensor

forward_shortcut(x: torch.Tensor) torch.Tensor[源代码]

Forward the shortcut branch.

参数

x (Tensor) – Input tensor with shape (n, c, h, w).

返回

Forward results.

返回类型

Tensor

init_weights()[源代码]

Initialize weights.

class mmedit.models.editors.sagan.sagan_modules.SNConditionNorm(in_channels, num_classes, use_cbn=True, norm_cfg=dict(type='BN'), cbn_norm_affine=False, auto_sync_bn=True, with_spectral_norm=False, sn_style='torch', norm_eps=0.0001, sn_eps=1e-12, init_cfg=dict(type='BigGAN'))[源代码]

Bases: torch.nn.Module

Conditional Normalization for SNGAN / Proj-GAN. The implementation refers to.

https://github.com/pfnet-research/sngan_projection/blob/master/source/links/conditional_batch_normalization.py # noda

and

https://github.com/POSTECH-CVLab/PyTorch-StudioGAN/blob/master/src/utils/model_ops.py # noqa

参数
  • in_channels (int) – Number of the channels of the input feature map.

  • num_classes (int) – Number of the classes in the dataset. If use_cbn is True, num_classes must larger than 0.

  • use_cbn (bool, optional) – Whether use conditional normalization. If use_cbn is True, two embedding layers would be used to mapping label to weight and bias used in normalization process.

  • norm_cfg (dict, optional) – Config for normalization method. Defaults to dict(type='BN').

  • cbn_norm_affine (bool) – Whether set affine=True when use conditional batch norm. This argument only work when use_cbn is True. Defaults to False.

  • auto_sync_bn (bool, optional) – Whether convert Batch Norm to Synchronized ones when Distributed training is on. Defaults to True.

  • with_spectral_norm (bool, optional) – whether use spectral norm for conv blocks and norm layers. Defaults to true.

  • norm_eps (float, optional) – eps for Normalization layers (both conditional and non-conditional ones). Defaults to 1e-4.

  • sn_style (str, optional) – The style of spectral normalization. If set to ajbrock, implementation by ajbrock(https://github.com/ajbrock/BigGAN-PyTorch/blob/master/layers.py) will be adopted. If set to torch, implementation by PyTorch will be adopted. Defaults to torch.

  • sn_eps (float, optional) – eps for spectral normalization operation. Defaults to 1e-12.

  • init_cfg (dict, optional) – Config for weight initialization. Defaults to dict(type='BigGAN').

forward(x, y=None)[源代码]

Forward function.

参数
  • x (Tensor) – Input tensor with shape (n, c, h, w).

  • y (Tensor, optional) – Input label with shape (n, ). Default None.

返回

Forward results.

返回类型

Tensor

init_weights()[源代码]

Initialize weights.

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

Free document hosting provided by Read the Docs.