How can I use table layers in torch to create my own network?

ⅰ亾dé卋堺 提交于 2019-12-23 05:12:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!