class
ZeroPad2d
extends
ConstantPad2dZeroPad2d(padding: int | tuple[int, int, int, int])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.valuefloatAlways
0.0.Notes
- Input: .
- Output: .
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),
... )