class
CircularPad2d
extends
ModuleCircularPad2d(padding: int | tuple[int, int, int, int])Pad a 4-D tensor (N, C, H, W) with wrap-around in both spatial axes.
Circular padding in 2-D treats both the height and width axes as periodic: pixels from the right column wrap to the left, and pixels from the bottom row wrap to the top.
Parameters
paddingint or tuple[int, int, int, int](left, right, top, bottom) circular padding sizes. A single
int pads equally on all four sides.Attributes
paddingtuple[int, int, int, int]Normalised
(left, right, top, bottom) padding.Notes
- Input: .
- Output: .
- Useful for processing panoramic (360°) images where left and right edges are physically adjacent, or for convolutional processing of spherical data projected to a 2-D grid.
- Combining circular padding with a stride-2 convolution on a toroidal feature map maintains the topology of the feature space.
Examples
**Seamless tiling convolution for a panoramic image:**
>>> import lucid
>>> import lucid.nn as nn
>>>
>>> pad = nn.CircularPad2d(padding=(2, 2, 0, 0)) # horizontal wrap only
>>> x = lucid.zeros(1, 3, 256, 512)
>>> pad(x).shape
(1, 3, 256, 516)
**Uniform circular border:**
>>> pad = nn.CircularPad2d(padding=1)
>>> x = lucid.zeros(4, 16, 32, 32)
>>> pad(x).shape
(4, 16, 34, 34)Methods (3)
dunder
__init__
→None__init__(padding: int | tuple[int, int, int, int])Initialise the CircularPad2d 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.