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)Used by 1
Constructors
1Instance methods
2Return a string representation of the layer's configuration.