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)[源代码]¶
Bases:
mmengine.model.BaseModule
Equalized LR Linear Module with Activation Layer.
This module is modified from
EqualizedLRLinearModule
defined in PGGAN. The major features updated in this module is adding support for activation layers used in StyleGAN2.- 参数
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)[源代码]¶
Bases:
mmengine.model.BaseModule
Noise Injection Module.
In StyleGAN2, they adopt this module to inject spatial random noise map in the generators.
- 参数
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)[源代码]¶
Forward Function.
- 参数
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.
- 返回
Output features.
- 返回类型
Tensor
- class mmagic.models.editors.stylegan1.stylegan1_modules.ConstantInput(channel, size=4)[源代码]¶
Bases:
mmengine.model.BaseModule
Constant Input.
In StyleGAN2, they substitute the original head noise input with such a constant input module.
- 参数
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)[源代码]¶
Bases:
mmengine.model.BaseModule
Blur module.
This module is adopted rightly after upsampling operation in StyleGAN2.
- 参数
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)[源代码]¶
Bases:
mmengine.model.BaseModule
Adaptive Instance Normalization Module.
Ref: https://github.com/rosinality/style-based-gan-pytorch/blob/master/model.py # noqa
- 参数
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)[源代码]¶
Bases:
mmengine.model.BaseModule
Base module for all modules in openmmlab.
BaseModule
is a wrapper oftorch.nn.Module
with additional functionality of parameter initialization. Compared withtorch.nn.Module
,BaseModule
mainly 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
.
备注
PretrainedInit
has a higher priority than any other initializer. The loaded pretrained weights will overwrite the previous initialized weights.- 参数
init_cfg (dict or List[dict], optional) – Initialization config dict.
- forward(x, style1, style2, noise1=None, noise2=None, return_noise=False)[源代码]¶
Forward function.
- 参数
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,
noise1
andnoise2
False. (will be returned with out. Defaults to) –
- 返回
Forward results.
- 返回类型
Tensor | tuple[Tensor]