就像文档所说的“当提供nInputDim时,大于该值的输入将被视为批量,其中实际要填充的dim将是尺寸dim +1。”我的理解是输入的维度比提供的nInputDim大,维度dim会变成dim + 1,但为什么呢?
发布于 2017-11-26 09:09:36
顺便说一下,我认为你提到的文档应该是this link。
假设您想在1(第一个) dim的末尾设置3个默认的零填充,因此您将创建一个填充模块,如下所示:
require 'nn';
dim = 1
pad = 3
module = nn.Padding(dim, pad)
given_tensor = torch.ones(4, 2)
print(given_tensor)
res_tensor = module:forward(given_tensor)
print(res_tensor)
如果你在torch解释器中运行这些行,你会得到如下结果,当你将4x2张量转换为7x2张量时,你成功地在1(第一个)维度添加了3个填充。
1 1
1 1
1 1
1 1
[torch.DoubleTensor of size 4x2]
1 1
1 1
1 1
1 1
0 0
0 0
0 0
[torch.DoubleTensor of size 7x2]
如果将 nInputDim
指定为1会发生什么情况,如下所示?
require 'nn';
dim = 1
pad = 3
nInputDim = 1
module = nn.Padding(dim, pad, nInputDim)
given_tensor = torch.ones(4, 2)
print(given_tensor)
res_tensor = module:forward(given_tensor)
print(res_tensor)
如果你运行它们,你会得到如下结果
1 1
1 1
1 1
1 1
[torch.DoubleTensor of size 4x2]
1 1 0 0 0
1 1 0 0 0
1 1 0 0 0
1 1 0 0 0
[torch.DoubleTensor of size 4x5]
你希望nInputDim
是1,但你的输入Dim是2,它将第一个维度4
作为批量大小,并对批量中的每个项目进行3个填充,它使4个大小的2个张量变成4个大小的5个张量。它的工作原理就像你对张量4x2的2(dim = dim + 1,second)进行3填充,这将输出相同的结果4x5。
https://stackoverflow.com/questions/47424230
复制相似问题