class
ReplicationPad2d
extends
ModuleReplicationPad2d(padding: int | tuple[int, int, int, int])Pad a 4-D tensor (N, C, H, W) by replicating the edge pixels.
Each out-of-bounds position is filled with the value of the nearest in-bounds pixel. Corner out-of-bounds positions replicate the nearest corner pixel.
Parameters
paddingint or tuple[int, int, int, int](left, right, top, bottom) replication 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: .
- Replication padding is preferred over zero padding in networks that process images with meaningful content close to the borders (e.g. panoramic or satellite imagery) because it avoids introducing a dark border artefact that the network would need to learn to ignore.
Examples
**Replicate borders before a 5×5 convolution:**
>>> import lucid
>>> import lucid.nn as nn
>>>
>>> pad = nn.ReplicationPad2d(padding=2)
>>> conv = nn.Conv2d(3, 32, kernel_size=5)
>>> x = lucid.zeros(1, 3, 64, 64)
>>> conv(pad(x)).shape # same-size output
(1, 32, 64, 64)
**Asymmetric replication:**
>>> pad = nn.ReplicationPad2d(padding=(0, 0, 1, 1)) # top and bottom only
>>> x = lucid.zeros(4, 16, 30, 30)
>>> pad(x).shape
(4, 16, 32, 30)Used by 1
Constructors
1Instance methods
2Return a string representation of the layer's configuration.