mmagic.models.editors.pggan.pggan_generator
¶
Module Contents¶
Classes¶
Generator for PGGAN. |
- class mmagic.models.editors.pggan.pggan_generator.PGGANGenerator(noise_size, out_scale, label_size=0, base_channels=8192, channel_decay=1.0, max_channels=512, fused_upconv=True, conv_module_cfg=None, fused_upconv_cfg=None, upsample_cfg=None)[source]¶
Bases:
mmengine.model.BaseModule
Generator for PGGAN.
- Parameters
noise_size (int) – Size of the input noise vector.
out_scale (int) – Output scale for the generated image.
label_size (int, optional) – Size of the label vector. Defaults to 0.
base_channels (int, optional) – The basic channel number of the generator. The other layers contains channels based on this number. Defaults to 8192.
channel_decay (float, optional) – Decay for channels of feature maps. Defaults to 1.0.
max_channels (int, optional) – Maximum channels for the feature maps in the generator block. Defaults to 512.
fused_upconv (bool, optional) – Whether use fused upconv. Defaults to True.
conv_module_cfg (dict, optional) – Config for the convolution module used in this generator. Defaults to None.
fused_upconv_cfg (dict, optional) – Config for the fused upconv module used in this generator. Defaults to None.
upsample_cfg (dict, optional) – Config for the upsampling operation. Defaults to None.
- _get_torgb_layer(in_channels: int)[source]¶
Get the to-rgb layer based on in_channels.
- Parameters
in_channels (int) – Number of input channels.
- Returns
To-rgb layer.
- Return type
nn.Module
- _num_out_channels(log_scale: int)[source]¶
Calculate the number of output channels based on logarithm of current scale.
- Parameters
log_scale (int) – The logarithm of the current scale.
- Returns
The current number of output channels.
- Return type
int
- _get_upconv_block(in_channels, log_scale)[source]¶
Get the conv block for upsampling.
- Parameters
in_channels (int) – The number of input channels.
log_scale (int) – The logarithmic of the current scale.
- Returns
The conv block for upsampling.
- Return type
nn.Module
- forward(noise, label=None, num_batches=0, return_noise=False, transition_weight=1.0, curr_scale=- 1)[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, theNone
indicates to use the default noise sampler.label (Tensor, optional) – Label vector with shape [N, C]. Defaults to None.
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 withfake_img
. Defaults to False.transition_weight (float, optional) – The weight used in resolution transition. Defaults to 1.0.
curr_scale (int, optional) – The scale for the current inference or training. Defaults to -1.
- Returns
- If not
return_noise
, only the output image will be returned. Otherwise, a dict contains
fake_img
andnoise_batch
will be returned.
- If not
- Return type
torch.Tensor | dict