ConstantPad2d#
- class brainstate.nn.ConstantPad2d(padding, value=0, in_size=None, name=None)[source]#
Pads the input tensor with a constant value.
- Parameters:
padding (
int|Sequence[int]) –The size of the padding. Can be:
int: same padding for all sides
Sequence[int] of length 2: (height_pad, width_pad)
Sequence[int] of length 4: (height_before, height_after, width_before, width_after)
Note
For the length-4 form, the first pair pads the first spatial axis (height) and the second pair pads the second spatial axis (width). This order is the REVERSE of
torch.nn.*Pad2d, which lists the last spatial axis (width) first as(left, right, top, bottom).value (
float) – The constant value to use for padding. Default is 0.in_size (
int|Sequence[int] |integer|Sequence[integer] |None) – The input size.
Examples
>>> import brainstate as brainstate >>> import jax.numpy as jnp >>> pad = brainstate.nn.ConstantPad2d(1, value=3.5) >>> input = jnp.ones((1, 4, 4, 3)) >>> output = pad(input) >>> print(output.shape) (1, 6, 6, 3)