Shortcuts

mmagic.models.editors.stylegan1.stylegan1_modules

Module Contents

Classes

EqualLinearActModule

Equalized LR Linear Module with Activation Layer.

NoiseInjection

Noise Injection Module.

ConstantInput

Constant Input.

Blur

Blur module.

AdaptiveInstanceNorm

Adaptive Instance Normalization Module.

StyleConv

Base module for all modules in openmmlab. BaseModule is a wrapper of

Functions

make_kernel(k)

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.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.

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.

forward(x)[source]

Forward function.

Parameters

x (Tensor) – Input feature map with shape of (N, C, …).

Returns

Output feature map.

Return type

Tensor

class mmagic.models.editors.stylegan1.stylegan1_modules.NoiseInjection(noise_weight_init=0.0, fixed_noise=False)[source]

Bases: mmengine.model.BaseModule

Noise 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.BaseModule

Constant 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.

forward(x)[source]

Forward function.

Parameters

x (Tensor) – Input feature map with shape of (N, C, …).

Returns

Output feature map.

Return type

Tensor

mmagic.models.editors.stylegan1.stylegan1_modules.make_kernel(k)[source]
class mmagic.models.editors.stylegan1.stylegan1_modules.Blur(kernel, pad, upsample_factor=1)[source]

Bases: mmengine.model.BaseModule

Blur 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.

forward(x)[source]

Forward function.

Parameters

x (Tensor) – Input feature map with shape of (N, C, H, W).

Returns

Output feature map.

Return type

Tensor

class mmagic.models.editors.stylegan1.stylegan1_modules.AdaptiveInstanceNorm(in_channel, style_dim)[source]

Bases: mmengine.model.BaseModule

Adaptive 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.

forward(input, style)[source]

Forward function.

Parameters
  • input (Tensor) – Input tensor with shape (n, c, h, w).

  • style (Tensor) – Input style tensor with shape (n, c).

Returns

Forward results.

Return type

Tensor

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.BaseModule

Base module for all modules in openmmlab. BaseModule is a wrapper of torch.nn.Module with additional functionality of parameter initialization. Compared with torch.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 the init_weights.

Note

PretrainedInit has 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, noise1 and noise2

  • False. (will be returned with out. Defaults to) –

Returns

Forward results.

Return type

Tensor | tuple[Tensor]

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.