tf.pad(input, paddings, name=None) 解析

来源:互联网 发布:淘宝用vr试穿 编辑:程序博客网 时间:2024/05/29 17:01

tf.pad(input, paddings, name=None)

官方解释:
Pads a tensor with zeros.
This operation pads a input with zeros according to the paddings you specify. paddings is an integer tensor with shape [Dn, 2], where n is the rank of input. For each dimension D of input, paddings[D, 0]indicates how many zeros to add before the contents of input in that dimension, and paddings[D, 1]indicates how many zeros to add after the contents of input in that dimension.

用例子解释一下,比如说 :

input = [[1, 1], [2, 2]] ,  shape =(2,2)paddings = [[1, 1], [2, 2]]  pad(t, paddings) ==> [[0, 0, 0, 0, 0]                      [0, 0, 0, 0, 0]                      [0, 1, 1, 0, 0]                     [[0, 2, 2, 0, 0]                      [0, 0, 0, 0, 0]]

依次解释上面的英文:

  1. paddings is an integer tensor with shape [Dn, 2]: 例子中 这个就是 [2, 2]

  2. where n is the rank of input.: 其实就是输入的维度,有2维,所以Dn = 2

  3. For each dimension D of input, paddings [D, 0] indicates how many zeors to add before the contents of input in that dimension :比如对于输入的第一维,这里也就代表行,那paddings[D, 0]代表:paddings [0, 0] ,paddings=[[1, 1], [2, 2]], paddings[0,0]索引的是[1,1] 左边的1。 也就是说,这个左边的1表示,在0这个维度(行)的前面(上面)加1个0。而paddings[1, 0] 索引的是 [2,2] 左边的2。表示在1这个维度(列)的前面(左面)加2个0.

  4. and paddings[D, 1]indicates how many zeros to add after the contents of input in that dimension. : 这个就也好理解 了。 比如D=0, paddings[0,1]索引的是 [1,1]右边的1, 这个1表示的是,在0这个维度(行)的后面(下面)加1个0。 而paddings[1,1]索引的是[2,2]右边的2。表示在1这个维度(列)的后面(右面)加2个0。

PS:有不对的请指出

阅读全文
1 0