filtered_lrelu: Filtered leaky ReLU for a batch of 2D images.

View source: R/filtered_lrelu.R

filtered_lreluR Documentation

Filtered leaky ReLU for a batch of 2D images.

Description

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.

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

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

  6. Apply leaky ReLU activation function to each value.

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

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

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

Usage

filtered_lrelu(
  x,
  fu = NULL,
  fd = NULL,
  b = NULL,
  up = 1,
  down = 1,
  padding = 0,
  gain = sqrt(2),
  slope = 0.2,
  clamp = NULL,
  flip_filter = FALSE,
  impl = if (cuda_is_available()) "cuda" else "ref"
)

Arguments

x

Float32/float16/float64 input tensor of the shape c(batch_size, num_channels, in_height, in_width).

fu

Float32 upsampling FIR filter of the shape c(filter_height, filter_width) (non-separable), filter_taps (separable), or NULL (identity).

fd

Float32 downsampling FIR filter of the shape c(filter_height, filter_width) (non-separable), filter_taps (separable), or NULL (identity).

b

Bias vector, or NULL 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. Can be a single integer or a vector of integers c(x, y) (default: 1).

down

Integer downsampling factor. Can be a single int or a vector c(x, y) (default: 1).

padding

Padding with respect to the upsampled image. Can be a single number or a vector c(x, y) or c(x_before, x_after, y_before, y_after) (default: 0).

gain

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

slope

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

clamp

Maximum magnitude for leaky ReLU output (default: NULL).

flip_filter

FALSE = convolution, TRUE = correlation (default: FALSE).

impl

Implementation to use. Can be 'ref' or 'cuda' (default: 'cuda' if torch::cuda_is_available() == TRUE, 'ref' otherwise).

Value

Tensor of the shape c(batch_size, num_channels, out_height, out_width).


rdinnager/styleganr documentation built on Nov. 9, 2022, 6:09 a.m.