https://github.com/torch/nngraph/issues/131
require 'nn'
require 'nngraph'
require 'rnn'
function make_net()
local mlp = nn.Sequential(); -- make a multi-layer perceptron
mlp:add(nn.MaskZero(nn.Linear(100, 5),1))
mlp:add(nn.MaskZero(nn.Tanh(),1))
mlp:add(nn.MaskZero(nn.Linear(5, 10),1))
h1 = nn.Identity()()
h2 = mlp(h1):annotate{name ='mlp_layer', description = 'mlp layer'}
return(nn.gModule({h1}, {h2}))
end
function main()
local nnmodule = make_net()
x = torch.rand(20,100)
print(nnmodule.forwardnodes)
for _, node in ipairs(nnmodule.forwardnodes) do
if node.data.annotations.name == 'mlp_layer' then
--node.data.module.weight:fill(1.0)
for i = 1,3 do
print(node.data.module.modules[i])
print(node.data.module.modules[i].modules)
end
end
end
nnmodule:updateOutput(x)
end
main()