将张量的 AAABBB table 转换为 Torch 中张量的嵌套 ABABAB table

Transform AAABBB table of tensors into nested ABABAB table of tensors in Torch

我试图解决这个问题已经有一段时间了,但仍然没有找到解决办法,也许有人可以帮我解决这个问题。我有以下 AAABBB 输入 table 到神经网络:

{
  1 : 
    {
      1 : DoubleTensor - size: 32x200
      2 : DoubleTensor - size: 32x200
      3 : DoubleTensor - size: 32x200
    }
  2 : 
    {
      1 : DoubleTensor - size: 32x54
      2 : DoubleTensor - size: 32x54
      3 : DoubleTensor - size: 32x54
    }
}

上面的table经过预处理后需要转化为嵌套ABABAB输入table:

{
  1 : 
    {
      1 : DoubleTensor - size: 32x200
      2 : DoubleTensor - size: 32x54
    }
  2 :
    {
      1 : DoubleTensor - size: 32x200
      2 : DoubleTensor - size: 32x54
    }
  3 :
    {
      1 : DoubleTensor - size: 32x200
      2 : DoubleTensor - size: 32x54        
    }
}

如何将 AAABBB table 转换为 ABABAB nested table 网络中使用 Torch table layers

似乎 dpnn 包中包含一个 Container 正是这样做的。 ZipTable 将 table 个 table 压缩成 table 个 table。

这是一个如何将 AAABBB table 转换为 ABABAB 嵌套 table 的工作示例。

require 'dpnn'

aaa = torch.DoubleTensor(3,32,200)
bbb = torch.DoubleTensor(3,32,54)

model = nn.Sequential()
par = nn.ParallelTable()
par:add(nn.SplitTable(1))
par:add(nn.SplitTable(1))
model:add(par)
model:add(nn.ZipTable())
model:forward({aaa,bbb})