pad

dragon.vm.tensorflow.pad(
  tensor,
  paddings,
  mode='CONSTANT',
  constant_values=0,
  name=None
)[source]

Pad the input according to the given sizes.

paddings should be a sequence with \(N\) tuples, where \(N\) is the number of input dimensions:

x = tf.ones(shape=(2, 3))
print(tf.pad(x, [[0, 1], [1, 0]]))  # Ok, (2, 3) -> (3, 4)
print(tf.pad(x, [[0, 1]]))  # Wrong

Following padding modes are supported:

x = tf.constant([[1, 2, 3], [4, 5, 6]])

# ConstantPad
print(tf.pad(x, [[0, 1], [1, 0]], 'CONSTANT', 9))

# ReflectPad
print(tf.pad(x, [[0, 1], [1, 0]], 'REFLECT'))
Parameters:
  • tensor (dragon.Tensor) The input tensor.
  • paddings (Sequence[Tuple[int]]) The begins and ends of padding.
  • mode ({'CONSTANT', 'REFLECT'}, optional) The padding mode.
  • constant_values (int, optional, default=0) The constant value in CONSTANT mode.
  • name (str, optional) The operation name.
Returns:

dragon.Tensor The output tensor.