Shortcuts

mmedit.models.editors.stylegan3.stylegan3_ops.ops.upfirdn2d

Custom PyTorch ops for efficient resampling of 2D images.

Module Contents

Functions

_init()

_parse_scaling(scaling)

parse scaling into list [x, y]

_parse_padding(padding)

parse padding into list [padx0, padx1, pady0, pady1]

_get_filter_size(f)

get width and height of filter kernel.

setup_filter(f[, device, normalize, flip_filter, ...])

Convenience function to setup 2D FIR filter for upfirdn2d().

upfirdn2d(x, f[, up, down, padding, flip_filter, ...])

Pad, upsample, filter, and downsample a batch of 2D images.

_upfirdn2d_ref(x, f[, up, down, padding, flip_filter, ...])

Slow reference implementation of upfirdn2d() using standard PyTorch

_upfirdn2d_cuda([up, down, padding, flip_filter, gain])

Fast CUDA implementation of upfirdn2d() using custom ops.

filter2d(x, f[, padding, flip_filter, gain, impl])

Filter a batch of 2D images using the given 2D FIR filter.

upsample2d(x, f[, up, padding, flip_filter, gain, impl])

Upsample a batch of 2D images using the given 2D FIR filter.

downsample2d(x, f[, down, padding, flip_filter, gain, ...])

Downsample a batch of 2D images using the given 2D FIR filter.

Attributes

_plugin

_upfirdn2d_cuda_cache

mmedit.models.editors.stylegan3.stylegan3_ops.ops.upfirdn2d._plugin[source]
mmedit.models.editors.stylegan3.stylegan3_ops.ops.upfirdn2d._init()[source]
mmedit.models.editors.stylegan3.stylegan3_ops.ops.upfirdn2d._parse_scaling(scaling)[source]

parse scaling into list [x, y]

mmedit.models.editors.stylegan3.stylegan3_ops.ops.upfirdn2d._parse_padding(padding)[source]

parse padding into list [padx0, padx1, pady0, pady1]

mmedit.models.editors.stylegan3.stylegan3_ops.ops.upfirdn2d._get_filter_size(f)[source]

get width and height of filter kernel.

mmedit.models.editors.stylegan3.stylegan3_ops.ops.upfirdn2d.setup_filter(f, device=torch.device('cpu'), normalize=True, flip_filter=False, gain=1, separable=None)[source]

Convenience function to setup 2D FIR filter for upfirdn2d().

Parameters
  • f – Torch tensor, numpy array, or python list of the shape [filter_height, filter_width] (non-separable), [filter_taps] (separable), [] (impulse), or None (identity).

  • device – Result device (default: cpu).

  • normalize – Normalize the filter so that it retains the magnitude for constant input signal (DC)? (default: True).

  • flip_filter – Flip the filter? (default: False).

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

  • separable – Return a separable filter? (default: select automatically) .

Returns

Float32 tensor of the shape [filter_height, filter_width] (non-separable) or [filter_taps] (separable).

mmedit.models.editors.stylegan3.stylegan3_ops.ops.upfirdn2d.upfirdn2d(x, f, up=1, down=1, padding=0, flip_filter=False, gain=1, impl='cuda')[source]

Pad, upsample, filter, and downsample a batch of 2D images.

Performs the following sequence of operations for each channel:

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

2. 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 2D FIR filter (f), 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).

This sequence of operations bears close resemblance to

scipy.signal.upfirdn().

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

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

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

  • up – Integer upsampling factor. Can be a single int or a

  • list/tuple[x, y] (default: 1).

  • down – Integer downsampling factor. Can be a single int or a list/tuple [x, y] (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).

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

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

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

Returns

Tensor of the shape [batch_size, num_channels, out_height, out_width] .

mmedit.models.editors.stylegan3.stylegan3_ops.ops.upfirdn2d._upfirdn2d_ref(x, f, up=1, down=1, padding=0, flip_filter=False, gain=1)[source]

Slow reference implementation of upfirdn2d() using standard PyTorch ops.

mmedit.models.editors.stylegan3.stylegan3_ops.ops.upfirdn2d._upfirdn2d_cuda_cache[source]
mmedit.models.editors.stylegan3.stylegan3_ops.ops.upfirdn2d._upfirdn2d_cuda(up=1, down=1, padding=0, flip_filter=False, gain=1)[source]

Fast CUDA implementation of upfirdn2d() using custom ops.

mmedit.models.editors.stylegan3.stylegan3_ops.ops.upfirdn2d.filter2d(x, f, padding=0, flip_filter=False, gain=1, impl='cuda')[source]

Filter a batch of 2D images using the given 2D FIR filter.

By default, the result is padded so that its shape matches the input. User-specified padding is applied on top of that, with negative values indicating cropping. Pixels outside the image are assumed to be zero.

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

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

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

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

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

  • impl – Implementation to use. Can be ‘ref’ or ‘cuda’

  • (default‘cuda’).

Returns

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

out_width]`.

mmedit.models.editors.stylegan3.stylegan3_ops.ops.upfirdn2d.upsample2d(x, f, up=2, padding=0, flip_filter=False, gain=1, impl='cuda')[source]

Upsample a batch of 2D images using the given 2D FIR filter.

By default, the result is padded so that its shape is a multiple of the input. User-specified padding is applied on top of that, with negative values indicating cropping. Pixels outside the image are assumed to be zero.

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

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

  • up – Integer upsampling factor. Can be a single int or a list/tuple [x, y] (default: 1).

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

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

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

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

Returns

Tensor of the shape [batch_size, num_channels, out_height, out_width] .

mmedit.models.editors.stylegan3.stylegan3_ops.ops.upfirdn2d.downsample2d(x, f, down=2, padding=0, flip_filter=False, gain=1, impl='cuda')[source]

Downsample a batch of 2D images using the given 2D FIR filter.

By default, the result is padded so that its shape is a fraction of the input. User-specified padding is applied on top of that, with negative values indicating cropping. Pixels outside the image are assumed to be zero.

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

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

  • down – Integer downsampling factor. Can be a single int or a list/tuple [x, y] (default: 1).

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

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

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

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

Returns

Tensor of the shape [batch_size, num_channels, out_height, out_width] .

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.