torch / nngraph

Graph Computation for nn

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to get access to intermediate node in nngraph?

blackyang opened this issue · comments

Sorry I didn't find related documentations. I would also apologize if github issues is not a good place to ask such questions (e.g if there is a google group for such discussions)

What I'd like to do is something similar to:

m = nn.Sequential()
m:add(nn.Linear(5,5))
m:get(1)

I have a rnn.GRU module in my gModule, and I have to manually call forget() function and change self.userPrevOutput sometimes. So it would be great if I can get access to intermediate node. Otherwise, I have to move rnn.GRU out of gModule :(

Thanks in advance!

Oh after taking a look at gmodule.lua code, I thinks I can do this:

m = nn.gModule()
m.forwardnodes[i].data.module

correct me if there is any problem :)

you can also take a look at https://github.com/bshillingford/nnquery for getting nodes from very large nngraph networks.

Thanks for the pointer!

Just saw this again, a better way I have found is to:

  1. add annotations by calling :annotate{name = 'name'} function
  2. find the annotated module, e.g.
for k, v in ipairs(model.forwardnodes) do
    if v.data.annotations.name == 'name' then
        module = v.data.module
    end
end

May I ask if I can get access to the output of intermediate layers?

@suhmily yes, simply module.outputs

btw, can also use

model.findModules('nn.Linear')[i]

to get the i-th nn.Linear module