如何使用割炬中的表层创建自己的网络? [英] How can I use table layers in torch to create my own network?
问题描述
我在torch7的nn包中卡住了,特别是它的表层。如何使用其ConcatTable,CAddTable或任何其他方法在下面创建网络?
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?
在这里,我的网络有两个分支,一个分支包含3个卷积层,另一个仅包含一层。我想对最后两个卷积层的输出求和(对第4卷积和第5卷积的输出求和),应该如何使用nn包编写我的割炬代码。
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.
推荐答案
假设您的分支正确实现:
Assuming your branches are implemented correctly:
local net = nn.Sequential()
:add(conv1)
:add(nn.ConcatTable()
:add(branch1)
:add(branch2))
:add(nn.CAddTable())
nn.CAddTable
与 nn.Sum
混淆。第一个接收张量表并返回所有张量的总和,而第二个接收一个张量并计算沿指定维度的元素之和。
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.
这篇关于如何使用割炬中的表层创建自己的网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!