Shortcuts

mmedit.models.editors.stylegan3.stylegan3_ops.ops.filtered_lrelu

Module Contents

Functions

_init()

_get_filter_size(f)

_parse_padding(padding)

filtered_lrelu(x[, fu, fd, b, up, down, padding, ...])

Filtered leaky ReLU for a batch of 2D images.

_filtered_lrelu_ref(x[, fu, fd, b, up, down, padding, ...])

Slow and memory-inefficient reference implementation of

_filtered_lrelu_cuda([up, down, padding, gain, slope, ...])

Fast CUDA implementation of filtered_lrelu() using custom ops.

Attributes

_plugin

_filtered_lrelu_cuda_cache

mmedit.models.editors.stylegan3.stylegan3_ops.ops.filtered_lrelu._plugin[源代码]
mmedit.models.editors.stylegan3.stylegan3_ops.ops.filtered_lrelu._init()[源代码]
mmedit.models.editors.stylegan3.stylegan3_ops.ops.filtered_lrelu._get_filter_size(f)[源代码]
mmedit.models.editors.stylegan3.stylegan3_ops.ops.filtered_lrelu._parse_padding(padding)[源代码]
mmedit.models.editors.stylegan3.stylegan3_ops.ops.filtered_lrelu.filtered_lrelu(x, fu=None, fd=None, b=None, up=1, down=1, padding=0, gain=np.sqrt(2), slope=0.2, clamp=None, flip_filter=False, impl='cuda')[源代码]

Filtered leaky ReLU for a batch of 2D images.

Performs the following sequence of operations for each channel:

  1. Add channel-specific bias if provided (b).

  2. Upsample the image by inserting N-1 zeros after each pixel (up).

  3. Pad the image with the specified number of zeros on each side

(padding). Negative padding corresponds to cropping the image.

  1. Convolve the image with the specified upsampling FIR filter (fu), shrinking it so that the footprint of all output pixels lies within the input image.

  2. Multiply each value by the provided gain factor (gain).

  3. Apply leaky ReLU activation function to each value.

7. Clamp each value between -clamp and +clamp, if clamp parameter is provided.

  1. Convolve the image with the specified downsampling FIR filter (fd), shrinking it so that the footprint of all output pixels lies within the input image.

  2. Downsample the image by keeping every Nth pixel (down).

The fused op is considerably more efficient than performing the same calculation using standard PyTorch ops. It supports gradients of arbitrary order.

参数
  • x – Float32/float16/float64 input tensor of the shape [batch_size, num_channels, in_height, in_width].

  • fu – Float32 upsampling FIR filter of the shape [filter_height, filter_width] (non-separable), [filter_taps] (separable), or None (identity).

  • fd – Float32 downsampling FIR filter of the shape [filter_height, filter_width] (non-separable), [filter_taps] (separable), or None (identity).

  • b – Bias vector, or None to disable. Must be a 1D tensor of the same type as x. The length of vector must must match the channel dimension of x.

  • up – Integer upsampling factor (default: 1).

  • down – Integer downsampling factor. (default: 1).

  • padding – Padding with respect to the upsampled image. Can be a single number or a list/tuple [x, y] or [x_before, x_after, y_before, y_after] (default: 0).

  • gain – Overall scaling factor for signal magnitude (default: sqrt(2)).

  • slope – Slope on the negative side of leaky ReLU (default: 0.2).

  • clamp – Maximum magnitude for leaky ReLU output (default: None).

  • flip_filter – False = convolution, True = correlation (default: False).

  • impl – Implementation to use. Can be ‘ref’ or ‘cuda’ (default: ‘cuda’).

返回

Tensor of the shape `[batch_size, num_channels, out_height,

out_width]`.

mmedit.models.editors.stylegan3.stylegan3_ops.ops.filtered_lrelu._filtered_lrelu_ref(x, fu=None, fd=None, b=None, up=1, down=1, padding=0, gain=np.sqrt(2), slope=0.2, clamp=None, flip_filter=False)[源代码]

Slow and memory-inefficient reference implementation of filtered_lrelu() using existing upfirdn2n() and bias_act() ops.

mmedit.models.editors.stylegan3.stylegan3_ops.ops.filtered_lrelu._filtered_lrelu_cuda_cache[源代码]
mmedit.models.editors.stylegan3.stylegan3_ops.ops.filtered_lrelu._filtered_lrelu_cuda(up=1, down=1, padding=0, gain=np.sqrt(2), slope=0.2, clamp=None, flip_filter=False)[源代码]

Fast CUDA implementation of filtered_lrelu() using custom ops.

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

Free document hosting provided by Read the Docs.