class
ConstantPad2d
extends
_ConstantPadNdConstantPad2d(padding: int | tuple[int, int, int, int], value: float)Pad a 4-D tensor (N, C, H, W) on all four spatial sides with a constant.
Adds padding around the height and width dimensions. The padding
tuple follows the convention (left, right, top, bottom):
Parameters
paddingint or tuple[int, int, int, int](left, right, top, bottom) padding sizes. A single int
applies the same amount on all four sides.valuefloatConstant fill value.
Attributes
paddingtuple[int, int, int, int]Normalised
(left, right, top, bottom) padding.valuefloatFill value.
Notes
- Input: .
- Output: .
Examples
**Uniform 2-pixel border padding:**
>>> import lucid
>>> import lucid.nn as nn
>>>
>>> pad = nn.ConstantPad2d(padding=2, value=0.0)
>>> x = lucid.zeros(1, 3, 28, 28)
>>> pad(x).shape
(1, 3, 32, 32)
**Asymmetric padding (e.g. to adjust receptive field alignment):**
>>> pad = nn.ConstantPad2d(padding=(1, 2, 0, 3), value=-999.0)
>>> x = lucid.zeros(2, 16, 10, 10)
>>> pad(x).shape
(2, 16, 13, 13) # H: 10+0+3=13, W: 10+1+2=13Methods (1)
dunder
__init__
→None__init__(padding: int | tuple[int, int, int, int], value: float)Initialise the ConstantPad2d module. See the class docstring for parameter semantics.