问题
I get stuck about nn package in torch7, especially its table layers. How can I use its ConcatTable, CAddTable or any other methods to create network below?
Here I have two branch of my network, one contains 3 convolution layers and another only one layer. I wanted to sum the outputs of my last two convolution layers(sum the output of convolution 4th and convolution 5th), how should write my torch code using nn package.
回答1:
Assuming your branches are implemented correctly:
local net = nn.Sequential()
:add(conv1)
:add(nn.ConcatTable()
:add(branch1)
:add(branch2))
:add(nn.CAddTable())
nn.CAddTable
is not to be confused with nn.Sum
. The first one receives a table of tensors and returns the summation of all tensor while the second one receives a single tensor and computes the sum of its elements along the specified dimension.
来源:https://stackoverflow.com/questions/42765486/how-can-i-use-table-layers-in-torch-to-create-my-own-network