【问题标题】:How to access intermediate layers' outputs using nngraph?如何使用 nngraph 访问中间层的输出?
【发布时间】:2016-12-01 15:42:01
【问题描述】:

我需要将损失函数应用于网络中的中间层 (L2) 表示,该网络在 L2 层之后有许多层。我知道如何访问 nngraph 中的网络输出,如下所示:

input = nn.Identity()()
net = nn.Sequential()
net:add(nn.Linear(100, 20)):add(nn.ReLU(true)) -- L1
net:add(nn.Linear(20, 10)):add(ReLU(true)) -- L2
net:add(nn.Linear(10, 2)) -- L3
output = net(input)

gmod = nn.gModule({input}, {output})

但是,我不知道如何访问第二层的结果并应用损失函数(标准)并以简洁的方式对其进行反向传播。谁能帮我解决这个问题?

【问题讨论】:

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


    【解决方案1】:

    您应该将您的层指定为单独的输出,然后您可以在任何给定时间访问它

    input = nn.Identity()()
    L1 = nn.ReLU(true)(nn.Linear(100, 20)(input))
    L2 = nn.ReLU(true)(nn.Linear(20, 10)(L1))
    L3 = nn.Linear(10, 2)(L2)
    
    gmod = nn.gModule({input}, {L3, L2})
    

    【讨论】:

      猜你喜欢
      • 2019-08-15
      • 2023-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-10
      相关资源
      最近更新 更多