填充张量。
用法
tf.pad(
tensor, paddings, mode='CONSTANT', constant_values=0, name=None
)参数
-
tensor一个Tensor。 -
paddingsTensor类型为int32。 -
mode"CONSTANT"、"REFLECT" 或 "SYMMETRIC" 之一(不区分大小写) -
constant_values在"CONSTANT" 模式下,要使用的标量填充值。必须与tensor的类型相同。 -
name操作的名称(可选)。
返回
-
一个
Tensor。具有与tensor相同的类型。
抛出
-
ValueError当模式不是 "CONSTANT"、"REFLECT" 或 "SYMMETRIC" 之一时。
此操作根据您指定的 paddings 填充 tensor。 paddings 是形状为 [n, 2] 的整数张量,其中 n 是 tensor 的秩。对于每个维度,input , paddings[D, 0]的D表示该维度中tensor的内容之前要添加多少个值,paddings[D, 1]表示该维度中tensor的内容之后要添加多少个值。如果 mode 是 "REFLECT" 则 paddings[D, 0] 和 paddings[D, 1] 都不得大于 tensor.dim_size(D) - 1 。如果 mode 是 "SYMMETRIC" 那么 paddings[D, 0] 和 paddings[D, 1] 必须不大于 tensor.dim_size(D) 。
输出的每个维度 D 的填充大小为:
paddings[D, 0] + tensor.dim_size(D) + paddings[D, 1]
例如:
t = tf.constant([[1, 2, 3], [4, 5, 6]])
paddings = tf.constant([[1, 1,], [2, 2]])
# 'constant_values' is 0.
# rank of 't' is 2.
tf.pad(t, paddings, "CONSTANT") # [[0, 0, 0, 0, 0, 0, 0],
# [0, 0, 1, 2, 3, 0, 0],
# [0, 0, 4, 5, 6, 0, 0],
# [0, 0, 0, 0, 0, 0, 0]]
tf.pad(t, paddings, "REFLECT") # [[6, 5, 4, 5, 6, 5, 4],
# [3, 2, 1, 2, 3, 2, 1],
# [6, 5, 4, 5, 6, 5, 4],
# [3, 2, 1, 2, 3, 2, 1]]
tf.pad(t, paddings, "SYMMETRIC") # [[2, 1, 1, 2, 3, 3, 2],
# [2, 1, 1, 2, 3, 3, 2],
# [5, 4, 4, 5, 6, 6, 5],
# [5, 4, 4, 5, 6, 6, 5]]
相关用法
- Python tf.parallel_stack用法及代码示例
- Python tf.print用法及代码示例
- Python tf.profiler.experimental.start用法及代码示例
- Python tf.profiler.experimental.Trace.set_metadata用法及代码示例
- Python tf.profiler.experimental.client.trace用法及代码示例
- Python tf.profiler.experimental.Trace用法及代码示例
- Python tf.py_function用法及代码示例
- Python tf.profiler.experimental.client.monitor用法及代码示例
- Python tf.profiler.experimental.Profile用法及代码示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代码示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代码示例
- Python tf.compat.v1.data.TFRecordDataset.interleave用法及代码示例
- Python tf.summary.scalar用法及代码示例
- Python tf.linalg.LinearOperatorFullMatrix.matvec用法及代码示例
- Python tf.linalg.LinearOperatorToeplitz.solve用法及代码示例
- Python tf.raw_ops.TPUReplicatedInput用法及代码示例
- Python tf.raw_ops.Bitcast用法及代码示例
- Python tf.compat.v1.distributions.Bernoulli.cross_entropy用法及代码示例
- Python tf.compat.v1.Variable.eval用法及代码示例
- Python tf.compat.v1.train.FtrlOptimizer.compute_gradients用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.pad。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
