有tensorflow.pad()的例子:
# 't' = is [[1, 2, 3], [4, 5, 6]]. # 'paddings' is [[1, 1,], [2, 2]]. # 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]]
我的问题是如何在输入的每个维度中填充零?而t的形状是[2,3],为什么pad()之后的输出是[4,x],‘4’是怎么来的? 谢谢你帮助我!!!
“填充”是 [[1, 1,], [2, 2]]。尝试将此值映射为 [[top,bottom],[left,right]]。 IE。
top = 1, //Extra padding introduce on top bottom = 1, //Extra padding introduce on bottom left = 2, //Extra padding introduce on left right = 2. //Extra padding introduce on right
尝试另一个示例,其中“填充”为 [[2, 1], [2, 3]]。 输出将是:
[[0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0] [0 0 1 2 3 0 0 0] [0 0 4 5 6 0 0 0] [0 0 0 0 0 0 0 0]]
这里上=2,下=1,左=2,右=3。