Shortcuts

mmagic.models.editors.lsgan.lsgan_generator

Module Contents

Classes

LSGANGenerator

Generator for LSGAN.

class mmagic.models.editors.lsgan.lsgan_generator.LSGANGenerator(output_scale=128, out_channels=3, base_channels=256, input_scale=8, noise_size=1024, conv_cfg=dict(type='ConvTranspose2d'), default_norm_cfg=dict(type='BN'), default_act_cfg=dict(type='ReLU'), out_act_cfg=dict(type='Tanh'), init_cfg=None)[source]

Bases: mmengine.model.BaseModule

Generator for LSGAN.

Implementation Details for LSGAN architecture:

  1. Adopt transposed convolution in the generator;

  2. Use batchnorm in the generator except for the final output layer;

  3. Use ReLU in the generator in addition to the final output layer;

  4. Keep channels of feature maps unchanged in the convolution backbone;

  5. Use one more 3x3 conv every upsampling in the convolution backbone.

We follow the implementation details of the origin paper: Least Squares Generative Adversarial Networks https://arxiv.org/pdf/1611.04076.pdf

Parameters
  • output_scale (int, optional) – Output scale for the generated image. Defaults to 128.

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

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

  • input_scale (int, optional) – The scale of the input 2D feature map. Defaults to 8.

  • noise_size (int, optional) – Size of the input noise vector. Defaults to 1024.

  • conv_cfg (dict, optional) – Config for the convolution module used in this generator. Defaults to dict(type=’ConvTranspose2d’).

  • default_norm_cfg (dict, optional) – Norm config for all of layers except for the final output layer. Defaults to dict(type=’BN’).

  • default_act_cfg (dict, optional) – Activation config for all of layers except for the final output layer. Defaults to dict(type=’ReLU’).

  • out_act_cfg (dict, optional) – Activation config for the final output layer. Defaults to dict(type=’Tanh’).

  • init_cfg (dict, optional) – Initialization config dict.

forward(noise, num_batches=0, return_noise=False)[source]

Forward function.

Parameters
  • noise (torch.Tensor | callable | None) – You can directly give a batch of noise through a torch.Tensor or offer a callable function to sample a batch of noise data. Otherwise, the None indicates to use the default noise sampler.

  • num_batches (int, optional) – The number of batch size. Defaults to 0.

  • return_noise (bool, optional) – If True, noise_batch will be returned in a dict with fake_img. Defaults to False.

Returns

If not return_noise, only the output image

will be returned. Otherwise, a dict contains fake_img and noise_batch will be returned.

Return type

torch.Tensor | dict

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.