Shortcuts

mmedit.models.editors.biggan.biggan_deep_discriminator

Module Contents

Classes

BigGANDeepDiscriminator

BigGAN-Deep Discriminator. The implementation refers to

class mmedit.models.editors.biggan.biggan_deep_discriminator.BigGANDeepDiscriminator(input_scale, num_classes=0, in_channels=3, out_channels=1, base_channels=96, block_depth=2, sn_eps=1e-06, sn_style='ajbrock', init_type='ortho', act_cfg=dict(type='ReLU', inplace=False), with_spectral_norm=True, blocks_cfg=dict(type='BigGANDeepDiscResBlock'), arch_cfg=None, pretrained=None)[源代码]

Bases: torch.nn.Module

BigGAN-Deep Discriminator. The implementation refers to https://github.com/ajbrock/BigGAN-PyTorch/blob/master/BigGANdeep.py # noqa.

The overall structure of BigGAN’s discriminator is the same with the projection discriminator.

The main difference between BigGAN and BigGAN-deep is that BigGAN-deep use more deeper residual blocks to construct the whole model.

More details can be found in: Large Scale GAN Training for High Fidelity Natural Image Synthesis (ICLR2019).

The design of the model structure is highly corresponding to the output resolution. For origin BigGAN-Deep’s generator, you can set output_scale as you need and use the default value of arch_cfg and blocks_cfg. If you want to customize the model, you can set the arguments in this way:

arch_cfg: Config for the architecture of this generator. You can refer the _default_arch_cfgs in the _get_default_arch_cfg function to see the format of the arch_cfg. Basically, you need to provide information of each block such as the numbers of input and output channels, whether to perform upsampling etc.

blocks_cfg: Config for the convolution block. You can adjust block params like channel_ratio here. You can also replace the block type to your registered customized block. However, you should notice that some params are shared between these blocks like act_cfg, with_spectral_norm, sn_eps etc.

参数
  • input_scale (int) – The scale of the input image.

  • num_classes (int, optional) – The number of conditional classes. Defaults to 0.

  • in_channels (int, optional) – The channel number of the input image. Defaults to 3.

  • out_channels (int, optional) – The channel number of the final output. Defaults to 1.

  • base_channels (int, optional) – The basic channel number of the discriminator. The other layers contains channels based on this number. Defaults to 96.

  • block_depth (int, optional) – The repeat times of Residual Blocks in each level of architecture. Defaults to 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.

  • init_type (str, optional) – The name of an initialization method: ortho | N02 | xavier. Defaults to ‘ortho’.

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

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

  • blocks_cfg (dict, optional) – Config for the convolution block. Defaults to dict(type=’BigGANDiscResBlock’).

  • arch_cfg (dict, optional) – Config for the architecture of this discriminator. Defaults to None.

  • pretrained (str | dict, optional) – Path for the pretrained model or dict containing information for pretained models whose necessary key is ‘ckpt_path’. Besides, you can also provide ‘prefix’ to load the generator part from the whole state dict. Defaults to None.

_get_default_arch_cfg(input_scale, base_channels)[源代码]
forward(x, label=None)[源代码]

Forward function.

参数
  • x (torch.Tensor) – Fake or real image tensor.

  • label (torch.Tensor | None) – Label Tensor. Defaults to None.

返回

Prediction for the reality of the input image with

given label.

返回类型

torch.Tensor

init_weights(pretrained=None, init_type='ortho')[源代码]

Init weights for models.

参数
  • pretrained (str | dict, optional) – Path for the pretrained model or dict containing information for pretained models whose necessary key is ‘ckpt_path’. Besides, you can also provide ‘prefix’ to load the generator part from the whole state dict. Defaults to None.

  • init_type (str, optional) – The name of an initialization method: ortho | N02 | xavier. Defaults to ‘ortho’.

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.