class
ReflectionPad1d
extends
ModuleReflectionPad1d(padding: _Size2d)Pad a 3-D tensor (N, C, L) by reflecting at the sequence boundaries.
Unlike constant padding, reflection padding mirrors the input signal itself at the boundary rather than filling with a fixed value. For a left pad of size , the new values at positions are set to respectively (the boundary pixel is excluded).
Parameters
paddingint or tuple[int, int](left, right) reflection padding sizes. Each value must be
strictly less than the corresponding input dimension. A single
int pads equally on both sides.Attributes
paddingtuple[int, int]Normalised
(left, right) padding.Notes
- Input: .
- Output: .
- Reflection padding avoids the abrupt discontinuity introduced by zero or constant padding, making it preferable for tasks sensitive to border artefacts (image style transfer, super-resolution).
- The padding size must be strictly less than the input size on the padded dimension.
Examples
**Mirror the ends of an audio waveform to avoid boundary clicks:**
>>> import lucid
>>> import lucid.nn as nn
>>>
>>> pad = nn.ReflectionPad1d(padding=4)
>>> x = lucid.zeros(2, 1, 1024) # (N, channels, T)
>>> pad(x).shape
(2, 1, 1032)
**Asymmetric reflection for causal-ish temporal convolution:**
>>> pad = nn.ReflectionPad1d(padding=(8, 0))
>>> x = lucid.zeros(4, 16, 200)
>>> pad(x).shape
(4, 16, 208)Methods (3)
dunder
__init__
→None__init__(padding: _Size2d)Initialise the ReflectionPad1d module. See the class docstring for parameter semantics.
fn
forward
→Tensorforward(x: Tensor)Pad the input tensor according to the configured padding.
Parameters
inputTensorInput tensor of shape .
Returns
TensorPadded tensor with spatial dimensions expanded by the configured padding amounts.
fn
extra_repr
→strextra_repr()Return a string representation of the layer's configuration.