理解するpad


公式ドキュメント
For each dimension D of input, paddings[D, 0] indicates how many values to add before the contents of tensor in that dimension, and paddings[D, 1] indicates how many values to add after the contents of tensor in that dimension.
ここでの[D,0]はどのように理解するかは,[:,0],例えば
paddings = tf.constant([[1, 1], [2, 2]])
paddings[:,0]

しゅつりょく
<tf.Tensor: id=00001, shape=(2,), dtype=int32, numpy=array([1, 2])>

この対応する次元間に追加するpadは、例えば例ではpaddings[:,0]=[1,2]を表し、最初の数はゼロ次元、すなわち2次元テンソルの中の行数であり、その値は1、すなわちゼロ次元の中で前のpad 1単位、2番目の数は1次元、すなわち2次元テンソルの中の列数であり、その値は2である.すなわち、最初の次元の前にpad 2単位があります.paddings[:,1]=[1,2]は、対応する次元の後にpad対応する単位である.2 Dテンソルの例は公式ドキュメントに表示されていますが、3 Dテンソルを見てみましょう.
t = tf.constant([[[1, 2, 3],[1,2,3],[1,2,3]], [[4, 5, 6],[4,5,6],[4,5,6]],[[7,8,9],[7,8,9],[7,8,9]]])

t tensor rank数と一致するためにpaddings[D,0]後に2つの数ではなく3つの数があるはずなので
paddings = tf.constant([[0, 0],[0, 0],[0, 2]])
paddings[:,0] == [0,0,2]
tf.pad(t, paddings, "CONSTANT")

しゅつりょく
<tf.Tensor: id=44136, shape=(3, 3, 5), dtype=int32, numpy=
array([[[1, 2, 3, 0, 0],
        [1, 2, 3, 0, 0],
        [1, 2, 3, 0, 0]],

       [[4, 5, 6, 0, 0],
        [4, 5, 6, 0, 0],
        [4, 5, 6, 0, 0]],

       [[7, 8, 9, 0, 0],
        [7, 8, 9, 0, 0],
        [7, 8, 9, 0, 0]]])>
paddings = tf.constant([[1, 0],[0, 0],[0, 0]])
paddings[:,0] == [1,0,0]
tf.pad(t, paddings, "CONSTANT")

しゅつりょく
<tf.Tensor: id=44138, shape=(4, 3, 3), dtype=int32, numpy=
array([[[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[1, 2, 3],
        [1, 2, 3],
        [1, 2, 3]],

       [[4, 5, 6],
        [4, 5, 6],
        [4, 5, 6]],

       [[7, 8, 9],
        [7, 8, 9],
        [7, 8, 9]]])>