class

ReplicationPad3d

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

Pad a 5-D tensor (N, C, D, H, W) by replicating the boundary voxels.

Extends the volume by repeating the nearest in-bounds voxel value along each of the six faces, with corners and edges replicated from the nearest valid voxel.

Parameters

paddingint or tuple[int, int, int, int, int, int]
(left, right, top, bottom, front, back) replication padding sizes. 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}}).

Examples

**Replicate 1 voxel on every face of a medical volume:**
>>> import lucid
>>> import lucid.nn as nn
>>>
>>> pad = nn.ReplicationPad3d(padding=1)
>>> x = lucid.zeros(1, 1, 64, 64, 64)
>>> pad(x).shape
(1, 1, 66, 66, 66)
**Pad only temporal (depth) faces for video models:**
>>> pad = nn.ReplicationPad3d(padding=(0, 0, 0, 0, 2, 2))
>>> x = lucid.zeros(2, 3, 8, 112, 112)
>>> pad(x).shape
(2, 3, 12, 112, 112)

Methods (3)

dunder

__init__

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

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