class

CircularPad2d

extendsModule
CircularPad2d(padding: int | tuple[int, int, int, int])
source

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.

output[n,c,i,j]=x ⁣[n,c,  (iptop)modH,  (jpleft)modW]\text{output}[n, c, i, j] = x\!\left[n, c,\; (i - p_{\text{top}}) \bmod H,\; (j - p_{\text{left}}) \bmod W \right]

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: (N,C,H,W)(N, C, H, W).
  • Output: (N,C,H+ptop+pbottom,W+pleft+pright)(N, C, H + p_{\text{top}} + p_{\text{bottom}}, W + p_{\text{left}} + p_{\text{right}}).
  • 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])
source

Initialise the CircularPad2d module. See the class docstring for parameter semantics.

fn

forward

Tensor
forward(x: Tensor)
source

Pad the input tensor according to the configured padding.

Parameters

inputTensor
Input tensor of shape (N,C,)(N, C, *).

Returns

Tensor

Padded tensor with spatial dimensions expanded by the configured padding amounts.

fn

extra_repr

str
extra_repr()
source

Return a string representation of the layer's configuration.