Shortcuts

mmedit.models.editors.biggan.biggan_modules

Module Contents

Classes

SNConvModule

Spectral Normalization ConvModule.

BigGANGenResBlock

Residual block used in BigGAN's generator.

BigGANConditionBN

Conditional Batch Normalization used in BigGAN.

SelfAttentionBlock

Self-Attention block used in BigGAN.

BigGANDiscResBlock

Residual block used in BigGAN's discriminator.

BigGANDeepGenResBlock

Residual block used in BigGAN-Deep's generator.

BigGANDeepDiscResBlock

Residual block used in BigGAN-Deep's discriminator.

class mmedit.models.editors.biggan.biggan_modules.SNConvModule(*args, with_spectral_norm=False, spectral_norm_cfg=None, **kwargs)[source]

Bases: mmcv.cnn.ConvModule

Spectral Normalization ConvModule.

In this module, we inherit default mmcv.cnn.ConvModule and adopt spectral normalization. The spectral normalization is proposed in: Spectral Normalization for Generative Adversarial Networks.

Parameters
  • with_spectral_norm (bool, optional) – Whether to use Spectral Normalization. Defaults to False.

  • spectral_norm_cfg (dict, optional) – Config for Spectral Normalization. Defaults to None.

class mmedit.models.editors.biggan.biggan_modules.BigGANGenResBlock(in_channels, out_channels, dim_after_concat, act_cfg=dict(type='ReLU'), upsample_cfg=dict(type='nearest', scale_factor=2), sn_eps=1e-06, sn_style='ajbrock', with_spectral_norm=True, input_is_label=False, auto_sync_bn=True)[source]

Bases: torch.nn.Module

Residual block used in BigGAN’s generator.

Parameters
  • in_channels (int) – The channel number of the input feature map.

  • out_channels (int) – The channel number of the output feature map.

  • dim_after_concat (int) – The channel number of the noise concatenated with the class vector.

  • act_cfg (dict, optional) – Config for the activation layer. Defaults to dict(type=’ReLU’).

  • upsample_cfg (dict, optional) – Config for the upsampling operation. Defaults to dict(type=’nearest’, scale_factor=2).

  • sn_eps (float, optional) – Epsilon value for spectral normalization. Defaults to 1e-6.

  • 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 ajbrock.

  • with_spectral_norm (bool, optional) – Whether to use spectral normalization in this block. Defaults to True.

  • input_is_label (bool, optional) – Whether the input of BNs’ linear layer is raw label instead of class vector. Defaults to False.

  • auto_sync_bn (bool, optional) – Whether to use synchronized batch normalization. Defaults to True.

forward(x, y)[source]

Forward function.

Parameters
  • x (torch.Tensor) – Input feature map tensor.

  • y (torch.Tensor) – Label tensor or class embedding concatenated with noise tensor.

Returns

Output feature map tensor.

Return type

torch.Tensor

class mmedit.models.editors.biggan.biggan_modules.BigGANConditionBN(num_features, linear_input_channels, bn_eps=1e-05, sn_eps=1e-06, sn_style='ajbrock', momentum=0.1, input_is_label=False, with_spectral_norm=True, auto_sync_bn=True)[source]

Bases: torch.nn.Module

Conditional Batch Normalization used in BigGAN.

Parameters
  • num_features (int) – The channel number of the input feature map tensor.

  • linear_input_channels (int) – The channel number of the linear layers’ input tensor.

  • bn_eps (float, optional) – Epsilon value for batch normalization. Defaults to 1e-5.

  • sn_eps (float, optional) – Epsilon value for spectral normalization. Defaults to 1e-6.

  • 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 ajbrock.

  • momentum (float, optional) – The value used for the running_mean and running_var computation. Defaults to 0.1.

  • input_is_label (bool, optional) – Whether the input of BNs’ linear layer is raw label instead of class vector. Defaults to False.

  • with_spectral_norm (bool, optional) – Whether to use spectral normalization. Defaults to True.

  • auto_sync_bn (bool, optional) – Whether to use synchronized batch normalization. Defaults to True.

forward(x, y)[source]

Forward function.

Parameters
  • x (torch.Tensor) – Input feature map tensor.

  • y (torch.Tensor) – Label tensor or class embedding concatenated with noise tensor.

Returns

Output feature map tensor.

Return type

torch.Tensor

class mmedit.models.editors.biggan.biggan_modules.SelfAttentionBlock(in_channels, with_spectral_norm=True, sn_eps=1e-06, sn_style='ajbrock')[source]

Bases: torch.nn.Module

Self-Attention block used in BigGAN.

Parameters
  • in_channels (int) – The channel number of the input feature map.

  • with_spectral_norm (bool, optional) – Whether to use spectral normalization. Defaults to True.

  • sn_eps (float, optional) – Epsilon value for spectral normalization. Defaults to 1e-6.

  • 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 ajbrock.

forward(x)[source]

Forward function.

Parameters

x (torch.Tensor) – Input feature map tensor.

Returns

Output feature map tensor.

Return type

torch.Tensor

class mmedit.models.editors.biggan.biggan_modules.BigGANDiscResBlock(in_channels, out_channels, act_cfg=dict(type='ReLU', inplace=False), sn_eps=1e-06, sn_style='ajbrock', with_downsample=True, with_spectral_norm=True, is_head_block=False)[source]

Bases: torch.nn.Module

Residual block used in BigGAN’s discriminator.

Parameters
  • in_channels (int) – The channel number of the input tensor.

  • out_channels (int) – The channel number of the output tensor.

  • act_cfg (dict, optional) – Config for the activation layer. Defaults to dict(type=’ReLU’, inplace=False).

  • sn_eps (float, optional) – Epsilon value for spectral normalization. Defaults to 1e-6.

  • 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 ajbrock.

  • with_downsample (bool, optional) – Whether to use downsampling in this block. Defaults to True.

  • with_spectral_norm (bool, optional) – Whether to use spectral normalization. Defaults to True.

  • is_head_block (bool, optional) – Whether this block is the first block of BigGAN. Defaults to False.

forward_sc(x)[source]

Forward function of shortcut.

Parameters

x (torch.Tensor) – Input feature map tensor.

Returns

Output tensor of shortcut.

Return type

torch.Tensor

forward(x)[source]

Forward function.

Parameters

x (torch.Tensor) – Input feature map tensor.

Returns

Output feature map tensor.

Return type

torch.Tensor

class mmedit.models.editors.biggan.biggan_modules.BigGANDeepGenResBlock(in_channels, out_channels, dim_after_concat, act_cfg=dict(type='ReLU'), upsample_cfg=dict(type='nearest', scale_factor=2), sn_eps=1e-06, sn_style='ajbrock', bn_eps=1e-05, with_spectral_norm=True, input_is_label=False, auto_sync_bn=True, channel_ratio=4)[source]

Bases: torch.nn.Module

Residual block used in BigGAN-Deep’s generator.

Parameters
  • in_channels (int) – The channel number of the input feature map.

  • out_channels (int) – The channel number of the output feature map.

  • dim_after_concat (int) – The channel number of the noise concatenated with the class vector.

  • act_cfg (dict, optional) – Config for the activation layer. Defaults to dict(type=’ReLU’).

  • upsample_cfg (dict, optional) – Config for the upsampling operation. Defaults to dict(type=’nearest’, scale_factor=2).

  • sn_eps (float, optional) – Epsilon value for spectral normalization. Defaults to 1e-6.

  • 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 ajbrock.

  • bn_eps (float, optional) – Epsilon value for batch normalization. Defaults to 1e-5.

  • with_spectral_norm (bool, optional) – Whether to use spectral normalization in this block. Defaults to True.

  • input_is_label (bool, optional) – Whether the input of BNs’ linear layer is raw label instead of class vector. Defaults to False.

  • auto_sync_bn (bool, optional) – Whether to use synchronized batch normalization. Defaults to True.

  • channel_ratio (int, optional) – The ratio of the input channels’ number to the hidden channels’ number. Defaults to 4.

forward(x, y)[source]

Forward function.

Parameters
  • x (torch.Tensor) – Input feature map tensor.

  • y (torch.Tensor) – Label tensor or class embedding concatenated with noise tensor.

Returns

Output feature map tensor.

Return type

torch.Tensor

class mmedit.models.editors.biggan.biggan_modules.BigGANDeepDiscResBlock(in_channels, out_channels, channel_ratio=4, act_cfg=dict(type='ReLU', inplace=False), sn_eps=1e-06, sn_style='ajbrock', with_downsample=True, with_spectral_norm=True)[source]

Bases: torch.nn.Module

Residual block used in BigGAN-Deep’s discriminator.

Parameters
  • in_channels (int) – The channel number of the input tensor.

  • out_channels (int) – The channel number of the output tensor.

  • channel_ratio (int, optional) – The ratio of the input channels’ number to the hidden channels’ number. Defaults to 4.

  • act_cfg (dict, optional) – Config for the activation layer. Defaults to dict(type=’ReLU’, inplace=False).

  • sn_eps (float, optional) – Epsilon value for spectral normalization. Defaults to 1e-6.

  • 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 ajbrock.

  • with_downsample (bool, optional) – Whether to use downsampling in this block. Defaults to True.

  • with_spectral_norm (bool, optional) – Whether to use spectral normalization. Defaults to True.

forward_sc(x)[source]

Forward function of shortcut.

Parameters

x (torch.Tensor) – Input feature map tensor.

Returns

Output tensor of shortcut.

Return type

torch.Tensor

forward(x)[source]

Forward function.

Parameters

x (torch.Tensor) – Input feature map tensor.

Returns

Output feature map tensor.

Return type

torch.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.