class

ReflectionPad3d

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

Pad a 5-D tensor (N, C, D, H, W) by reflecting at the volume boundaries.

Applies reflection padding simultaneously across the depth, height, and width dimensions of a volumetric tensor. Each out-of-bounds voxel receives the value of the voxel that is its mirror image with respect to the nearest valid face, excluding the boundary voxel itself.

Parameters

paddingint or tuple[int, int, int, int, int, int]
(left, right, top, bottom, front, back) reflection padding sizes. Each value must be strictly less than the size of the corresponding input dimension. A single int pads equally on all six faces.

Attributes

paddingtuple[int, int, int, int, int, int]
Normalised 6-element padding tuple.

Notes

  • Input: (N,C,D,H,W)(N, C, D, H, W).
  • Output: (N,C,Dout,Hout,Wout)(N, C, D_{\text{out}}, H_{\text{out}}, W_{\text{out}}).
  • Reflection padding in 3-D is useful for volumetric image analysis (CT/MRI scans) where zero-padding at volume boundaries would create artificial low-density regions that the network might spuriously learn to avoid.

Examples

**Pad a small 3-D patch for a 3×3×3 volumetric convolution:**
>>> import lucid
>>> import lucid.nn as nn
>>>
>>> pad = nn.ReflectionPad3d(padding=1)
>>> x = lucid.zeros(1, 4, 16, 16, 16)
>>> pad(x).shape
(1, 4, 18, 18, 18)
**Asymmetric 3-D reflection:**
>>> pad = nn.ReflectionPad3d(padding=(1, 1, 2, 2, 0, 0))
>>> x = lucid.zeros(2, 8, 10, 10, 10)
>>> pad(x).shape
(2, 8, 10, 14, 12)

Methods (3)

dunder

__init__

None
__init__(padding: int | tuple[int, int, int, int, int, int])
source

Initialise the ReflectionPad3d 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.