神经网络学习-tensoflow2.0-temsor的填充与复制

1.tf.pad(tensor,[[1a,1b],[2a,2b]...]):将tensor中的第n个维度上下分别增加na和nb个值

example:

input:

a=tf.random.uniform([2,2],maxval=5,minval=1,dtype=tf.int32)
b=tf.pad(a,[[1,1],[0,2]])

tf.print(a,'\n')
tf.print(b)

output:

[[3 3]
[4 2]]

[[0 0 0 0]
[3 3 0 0]
[4 2 0 0]
[0 0 0 0]]

input:

a=tf.random.uniform([4,28,28,3],maxval=5,minval=1,dtype=tf.int32)
b=tf.pad(a,[[1,1],[0,2],[0,0],[2,2]])

print(a.shape)
print(b.shape)

output:

(4, 28, 28, 3)
(6, 30, 28, 7)

 

2.tf.tile(tensor,[a0,a1,a2...]):将tensor的第n个维度复制为原来的an倍。

example:

input:

a=tf.random.uniform([4,28,28,3],maxval=5,minval=1,dtype=tf.int32)
b=tf.tile(a,[1,1,2,3])

print(a.shape)
print(b.shape)

output:

(4, 28, 28, 3)
(4, 28, 56, 9)

 

 

 

 

 

 

 

 

 




posted @ 2020-11-03 21:41  ladadee  阅读(124)  评论(0)    收藏  举报