pad¶
dragon.
pad
(
inputs,
pads,
mode='constant',
value=0,
**kwargs
)[source]¶Pad the input according to the given sizes.
pads
should be a sequence with \(N\) tuples, where \(N\) is the number of input dimensions:x = dragon.ones(shape=(2, 3)) print(dragon.pad(x, [[0, 1], [1, 0]])) # Ok, (2, 3) -> (3, 4) print(dragon.pad(x, [[0, 1]])) # Wrong
Following padding modes are supported:
x = dragon.constant([[1, 2, 3], [4, 5, 6]]) # ConstantPad print(dragon.pad(x, [[0, 1], [1, 0]], 'constant', 9)) # ReflectPad print(dragon.pad(x, [[0, 1], [1, 0]], 'reflect')) # EdgePad print(dragon.pad(x, [[0, 1], [1, 0]], 'edge'))
- Parameters:
- inputs (dragon.Tensor) – The input tensor.
- pads (Sequence[Tuple[int], Tuple[dragon.Tensor]]) – The padding begins and ends.
- mode ({'constant', 'reflect', 'edge'}, optional) – The padding mode.
- value (number, optional, default=0) – The value used in
'constant'
mode.
- Returns:
dragon.Tensor – The output tensor.