class

ZeroPad2d

extendsConstantPad2d
ZeroPad2d(padding: int | tuple[int, int, int, int])
source

Pad a 4-D tensor (N, C, H, W) with zeros on all four spatial sides.

Equivalent to ConstantPad2d(padding, value=0.0). The standard padding mode used before 2-D convolutions to preserve spatial resolution ('same' padding) or to prevent aliasing at image boundaries.

Parameters

paddingint or tuple[int, int, int, int]
(left, right, top, bottom) padding sizes. A single int pads equally on all four sides.

Attributes

paddingtuple[int, int, int, int]
Normalised (left, right, top, bottom) padding.
valuefloat
Always 0.0.

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

Examples

**1-pixel zero border for a 3×3 convolution:**
>>> import lucid
>>> import lucid.nn as nn
>>>
>>> pad = nn.ZeroPad2d(1)
>>> x = lucid.zeros(2, 64, 32, 32)
>>> pad(x).shape
(2, 64, 34, 34)
**Use inside a Sequential block before strided convolution:**
>>> block = nn.Sequential(
...     nn.ZeroPad2d(padding=(0, 1, 0, 1)),   # asymmetric for stride-2
...     nn.Conv2d(32, 64, kernel_size=3, stride=2),
... )

Methods (2)

dunder

__init__

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

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

fn

extra_repr

str
extra_repr()
source

Return a string representation of the layer's configuration.