t = tf.constant([[1, 2, 3], [4, 5, 6]])
paddings = tf.constant([[1, 1,], [2, 2]])
tf.pad(t, paddings, "CONSTANT")
<tf.Tensor 'Pad:0' shape=(4, 7) dtype=int32>
sess=tf.InteractiveSession()
c=tf.pad(t, paddings, "CONSTANT")
c.eval()
array([[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]])
paddings = tf.constant([[2, 1,], [2, 2]])表示再第一个维度 前面增加 2 第一个维度后面增加1 第二个维度前面增加2 后面增加 2
d=tf.pad(t, paddings, "CONSTANT")
d.eval()
array([[0, 0, 0, 0, 0, 0, 0],
[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() 是再 不同的维度 进行填充
猜你喜欢
转载自blog.csdn.net/candy134834/article/details/85920046
今日推荐
周排行