如何将张量分解为Torch中连续张量的表格?

时间:2016-06-17 21:48:05

标签: machine-learning lua torch conv-neural-network

我正在尝试拆分张量,然后使用nn.ParallelTable在分割张量上做一些事情。但是,nn.SplitTable使得分裂张量不连续,这对我来说是不可取的。

这是我的网络架构:

nn.Sequential {
  [input -> (1) -> (2) -> output]
  (1): nn.SplitTable
  (2): nn.ParallelTable {
    input
      |`-> (1): nn.Sequential {
      |      [input -> (1) -> (2) -> (3) -> output]
      |      (1): nn.View(20, 1, 6, 6)
      |      (2): nn.SpatialConvolution(1 -> 10, 2x2)
      |      (3): nn.ReLU
      |    }
      |`-> (2): nn.Sequential {
      |      [input -> (1) -> (2) -> (3) -> output]
      |      (1): nn.View(20, 1, 6, 6)
      |      (2): nn.SpatialConvolution(1 -> 10, 2x2)
      |      (3): nn.ReLU
      |    }
       ... -> output
  }

以下是制作它的代码:

parallelLayer = nn.ParallelTable()
parallelLayer:add(nn.Sequential():add(nn.View(20, 1, 6, 6)):add(nn.SpatialConvolution(1, 10, 2, 2)):add(nn.ReLU()))
parallelLayer:add(nn.Sequential():add(nn.View(20, 1, 6, 6)):add(nn.SpatialConvolution(1, 10, 2, 2)):add(nn.ReLU()))

net = nn.Sequential():add(nn.SplitTable(2))
net:add(parallelLayer)

在做正面传​​球之后: net:forward(torch.rand(20,2,6,6))

我收到以下错误:

/home/amir/torch/install/share/lua/5.1/torch/Tensor.lua:457: expecting a contiguous tensor
stack traceback:
    [C]: in function 'assert'
    /home/amir/torch/install/share/lua/5.1/torch/Tensor.lua:457: in function 'view'
    /home/amir/torch/install/share/lua/5.1/nn/View.lua:83: in function </home/amir/torch/install/share/lua/5.1/nn/View.lua:77>
    [C]: in function 'xpcall'
    /home/amir/torch/install/share/lua/5.1/nn/Container.lua:65: in function 'rethrowErrors'
    /home/amir/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function </home/amir/torch/install/share/lua/5.1/nn/Sequential.lua:41>
    [C]: in function 'xpcall'
    /home/amir/torch/install/share/lua/5.1/nn/Container.lua:65: in function 'rethrowErrors'
    /home/amir/torch/install/share/lua/5.1/nn/ParallelTable.lua:12: in function </home/amir/torch/install/share/lua/5.1/nn/ParallelTable.lua:10>
    [C]: in function 'xpcall'
    /home/amir/torch/install/share/lua/5.1/nn/Container.lua:65: in function 'rethrowErrors'
    /home/amir/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function 'forward'
    [string "_RESULT={net:forward(torch.rand(20, 2, 6, 6))}"]:1: in main chunk
    [C]: in function 'xpcall'
    /home/amir/torch/install/share/lua/5.1/trepl/init.lua:651: in function 'repl'
    ...amir/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:199: in main chunk
    [C]: at 0x00406670

但如果我这样做:

net:get(2):forward({torch.rand(20, 6, 6), torch.rand(20, 6, 6)})

我没有收到任何错误。有没有人对如何将输入张量分成连续张量有任何想法?或者我可能会问我如何连续分裂张量然后使用ParallelTable?有没有更好的方法来做到这一点,我不知道?

0 个答案:

没有答案