Shortcuts

mmedit.models.editors.mspie.mspie_stylegan2_modules

Module Contents

Classes

ModulatedPEConv2d

Modulated Conv2d in StyleGANv2 with Positional Encoding (PE).

ModulatedPEStyleConv

Modulated Style Convolution with Positional Encoding.

class mmedit.models.editors.mspie.mspie_stylegan2_modules.ModulatedPEConv2d(in_channels, out_channels, kernel_size, style_channels, demodulate=True, upsample=False, downsample=False, blur_kernel=[1, 3, 3, 1], equalized_lr_cfg=dict(mode='fan_in', lr_mul=1.0, gain=1.0), style_mod_cfg=dict(bias_init=1.0), style_bias=0.0, eps=1e-08, no_pad=False, deconv2conv=False, interp_pad=None, up_config=dict(scale_factor=2, mode='nearest'), up_after_conv=False)[source]

Bases: torch.nn.Module

Modulated Conv2d in StyleGANv2 with Positional Encoding (PE).

This module is modified from the ModulatedConv2d in StyleGAN2 to support the experiments in: Positional Encoding as Spatial Inductive Bias in GANs, CVPR’2021.

Parameters
  • in_channels (int) – Input channels.

  • out_channels (int) – Output channels.

  • kernel_size (int) – Kernel size, same as nn.Con2d.

  • style_channels (int) – Channels for the style codes.

  • demodulate (bool, optional) – Whether to adopt demodulation. Defaults to True.

  • upsample (bool, optional) – Whether to adopt upsampling in features. Defaults to False.

  • downsample (bool, optional) – Whether to adopt downsampling in features. Defaults to False.

  • blur_kernel (list[int], optional) – Blurry kernel. Defaults to [1, 3, 3, 1].

  • equalized_lr_cfg (dict | None, optional) – Configs for equalized lr. Defaults to dict(mode=’fan_in’, lr_mul=1., gain=1.).

  • style_mod_cfg (dict, optional) – Configs for style modulation module. Defaults to dict(bias_init=1.).

  • style_bias (float, optional) – Bias value for style code. Defaults to 0..

  • eps (float, optional) – Epsilon value to avoid computation error. Defaults to 1e-8.

  • no_pad (bool, optional) – Whether to removing the padding in convolution. Defaults to False.

  • deconv2conv (bool, optional) – Whether to substitute the transposed conv with (conv2d, upsampling). Defaults to False.

  • interp_pad (int | None, optional) – The padding number of interpolation pad. Defaults to None.

  • up_config (dict, optional) – Upsampling config. Defaults to dict(scale_factor=2, mode=’nearest’).

  • up_after_conv (bool, optional) – Whether to adopt upsampling after convolution. Defaults to False.

forward(x, style)[source]

Forward function.

Parameters
  • x ([Tensor) – Input features with shape of (N, C, H, W).

  • style (Tensor) – Style latent with shape of (N, C).

Returns

Output feature with shape of (N, C, H, W).

Return type

Tensor

class mmedit.models.editors.mspie.mspie_stylegan2_modules.ModulatedPEStyleConv(in_channels, out_channels, kernel_size, style_channels, upsample=False, blur_kernel=[1, 3, 3, 1], demodulate=True, style_mod_cfg=dict(bias_init=1.0), style_bias=0.0, **kwargs)[source]

Bases: torch.nn.Module

Modulated Style Convolution with Positional Encoding.

This module is modified from the ModulatedStyleConv in StyleGAN2 to support the experiments in: Positional Encoding as Spatial Inductive Bias in GANs, CVPR’2021.

Parameters
  • in_channels (int) – Input channels.

  • out_channels (int) – Output channels.

  • kernel_size (int) – Kernel size, same as nn.Con2d.

  • style_channels (int) – Channels for the style codes.

  • demodulate (bool, optional) – Whether to adopt demodulation. Defaults to True.

  • upsample (bool, optional) – Whether to adopt upsampling in features. Defaults to False.

  • downsample (bool, optional) – Whether to adopt downsampling in features. Defaults to False.

  • blur_kernel (list[int], optional) – Blurry kernel. Defaults to [1, 3, 3, 1].

  • equalized_lr_cfg (dict | None, optional) – Configs for equalized lr. Defaults to dict(mode=’fan_in’, lr_mul=1., gain=1.).

  • style_mod_cfg (dict, optional) – Configs for style modulation module. Defaults to dict(bias_init=1.).

  • style_bias (float, optional) – Bias value for style code. Defaults to 0..

forward(x, style, noise=None, return_noise=False)[source]

Forward Function.

Parameters
  • x ([Tensor) – Input features with shape of (N, C, H, W).

  • style (Tensor) – Style latent with shape of (N, C).

  • noise (Tensor, optional) – Noise for injection. Defaults to None.

  • return_noise (bool, optional) – Whether to return noise tensors. Defaults to False.

Returns

Output features with shape of (N, C, H, W)

Return type

Tensor

Read the Docs v: latest
Versions
master
latest
stable
zyh-re-docs
zyh-doc-notfound-extend
zyh-api-rendering
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.