tensorflow.pad如何工作? [英] How does tensorflow.pad work?

查看:109
本文介绍了tensorflow.pad如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有tensorflow.pad()的示例:

There is the example of 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如何出现?
感谢您的帮助!!!

my question is how to pad zeros in every dimention of input? And the shape of t is [2,3], why output after pad() is [4,x],how the '4' comes? Thanks for helping me!!!

推荐答案

文档对此非常清楚。 对于输入的每个维D,paddings [D,0]指示在该维中张量的内容之前要添加多少值,而paddings [D,1]指示在内容后的张量内容之前要添加多少值

The documentation is pretty clear about this. 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.


为什么输出是[4,x]?

why out put is [4, x]?

4是维度0的大小,维度0具有填充 [1,1] ,根据文档,其中在 t 的零维之前添加一个,在其后添加一个, t 的零维的大小为2, 2 +1 + 1 ,结果为4。即它分别在t的开头和结尾处填充了一个零行。与维度1类似,由于 padding [1] [2,2] ,因此在 t 的开头和结尾处添加了两个零列

4 is the size of dimension 0, dimension 0 has padding [1, 1], which according to the docs add one before the zero dimension of t and one after, the size of zero dimension of t is 2, 2 + 1 + 1, you have 4 in the result. i.e. it padded one zero row at the beginning and ending of t respectively. Similarly for dimension 1, since padding[1] is [2,2], two zero columns are added to t at the beginning and ending respectively.

这篇关于tensorflow.pad如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆