mmagic.models.editors.stylegan1.stylegan1_modules¶
Module Contents¶
Classes¶
Equalized LR Linear Module with Activation Layer. |
|
Noise Injection Module. |
|
Constant Input. |
|
Blur module. |
|
Adaptive Instance Normalization Module. |
|
Base module for all modules in openmmlab. |
Functions¶
|
- class mmagic.models.editors.stylegan1.stylegan1_modules.EqualLinearActModule(*args, equalized_lr_cfg=dict(gain=1.0, lr_mul=1.0), bias=True, bias_init=0.0, act_cfg=None, **kwargs)[source]¶
Bases:
mmengine.model.BaseModuleEqualized LR Linear Module with Activation Layer.
This module is modified from
EqualizedLRLinearModuledefined in PGGAN. The major features updated in this module is adding support for activation layers used in StyleGAN2.- Parameters
equalized_lr_cfg (dict | None, optional) – Config for equalized lr. Defaults to dict(gain=1., lr_mul=1.).
bias (bool, optional) – Whether to use bias item. Defaults to True.
bias_init (float, optional) – The value for bias initialization. Defaults to
0..act_cfg (dict | None, optional) – Config for activation layer. Defaults to None.
- class mmagic.models.editors.stylegan1.stylegan1_modules.NoiseInjection(noise_weight_init=0.0, fixed_noise=False)[source]¶
Bases:
mmengine.model.BaseModuleNoise Injection Module.
In StyleGAN2, they adopt this module to inject spatial random noise map in the generators.
- Parameters
noise_weight_init (float, optional) – Initialization weight for noise injection. Defaults to
0..fixed_noise (bool, optional) – Whether to inject a fixed noise. Defaults
False. (to) –
- forward(image, noise=None, return_noise=False)[source]¶
Forward Function.
- Parameters
image (Tensor) – Spatial features with a shape of (N, C, H, W).
noise (Tensor, optional) – Noises from the outside. Defaults to None.
return_noise (bool, optional) – Whether to return noise tensor. Defaults to False.
- Returns
Output features.
- Return type
Tensor
- class mmagic.models.editors.stylegan1.stylegan1_modules.ConstantInput(channel, size=4)[source]¶
Bases:
mmengine.model.BaseModuleConstant Input.
In StyleGAN2, they substitute the original head noise input with such a constant input module.
- Parameters
channel (int) – Channels for the constant input tensor.
size (int, optional) – Spatial size for the constant input. Defaults to 4.
- class mmagic.models.editors.stylegan1.stylegan1_modules.Blur(kernel, pad, upsample_factor=1)[source]¶
Bases:
mmengine.model.BaseModuleBlur module.
This module is adopted rightly after upsampling operation in StyleGAN2.
- Parameters
kernel (Array) – Blur kernel/filter used in UpFIRDn.
pad (list[int]) – Padding for features.
upsample_factor (int, optional) – Upsampling factor. Defaults to 1.
- class mmagic.models.editors.stylegan1.stylegan1_modules.AdaptiveInstanceNorm(in_channel, style_dim)[source]¶
Bases:
mmengine.model.BaseModuleAdaptive Instance Normalization Module.
Ref: https://github.com/rosinality/style-based-gan-pytorch/blob/master/model.py # noqa
- Parameters
in_channel (int) – The number of input’s channel.
style_dim (int) – Style latent dimension.
- class mmagic.models.editors.stylegan1.stylegan1_modules.StyleConv(in_channels, out_channels, kernel_size, style_channels, padding=1, initial=False, blur_kernel=[1, 2, 1], upsample=False, fused=False)[source]¶
Bases:
mmengine.model.BaseModuleBase module for all modules in openmmlab.
BaseModuleis a wrapper oftorch.nn.Modulewith additional functionality of parameter initialization. Compared withtorch.nn.Module,BaseModulemainly adds three attributes.init_cfg: the config to control the initialization.init_weights: The function of parameter initialization and recording initialization information._params_init_info: Used to track the parameter initialization information. This attribute only exists during executing theinit_weights.
Note
PretrainedInithas a higher priority than any other initializer. The loaded pretrained weights will overwrite the previous initialized weights.- Parameters
init_cfg (dict or List[dict], optional) – Initialization config dict.
- forward(x, style1, style2, noise1=None, noise2=None, return_noise=False)[source]¶
Forward function.
- Parameters
x (Tensor) – Input tensor.
style1 (Tensor) – Input style tensor with shape (n, c).
style2 (Tensor) – Input style tensor with shape (n, c).
noise1 (Tensor, optional) – Noise tensor with shape (n, c, h, w). Defaults to None.
noise2 (Tensor, optional) – Noise tensor with shape (n, c, h, w). Defaults to None.
return_noise (bool, optional) – If True,
noise1andnoise2False. (will be returned with out. Defaults to) –
- Returns
Forward results.
- Return type
Tensor | tuple[Tensor]