class

ConstantPad3d

extends_ConstantPadNd
ConstantPad3d(padding: int | tuple[int, int, int, int, int, int], value: float)
source

Pad a 5-D tensor (N, C, D, H, W) on all six faces with a constant.

Adds padding around the depth, height, and width dimensions. The padding tuple follows the convention (left, right, top, bottom, front, back):

Dout=D+pfront+pbackHout=H+ptop+pbottomWout=W+pleft+pright\begin{aligned} D_{\text{out}} &= D + p_{\text{front}} + p_{\text{back}} \\ H_{\text{out}} &= H + p_{\text{top}} + p_{\text{bottom}} \\ W_{\text{out}} &= W + p_{\text{left}} + p_{\text{right}} \end{aligned}

Parameters

paddingint or tuple[int, int, int, int, int, int]
(left, right, top, bottom, front, back) padding sizes. A single int applies the same amount on all six faces.
valuefloat
Constant fill value.

Attributes

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

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}}).

Examples

**Uniform 1-voxel border around a volumetric tensor:**
>>> import lucid
>>> import lucid.nn as nn
>>>
>>> pad = nn.ConstantPad3d(padding=1, value=0.0)
>>> x = lucid.zeros(1, 4, 16, 16, 16)
>>> pad(x).shape
(1, 4, 18, 18, 18)
**Pad only the depth axis (front/back) for temporal video data:**
>>> pad = nn.ConstantPad3d(padding=(0, 0, 0, 0, 2, 2), value=0.0)
>>> x = lucid.zeros(2, 3, 8, 32, 32)    # (N, C, T, H, W)
>>> pad(x).shape
(2, 3, 12, 32, 32)

Methods (1)

dunder

__init__

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

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