Naming features for Torch nn modules
luarock install nnname
nnname adds find()
findAll()
setName()
methods to nn.Module
, so please require nn
and dpnn
(optional) before nnname
as follows.
Also, it rewrites the __string()
function to show module name.
The name of a module is store at .name
variable.
require 'nn'
require 'dpnn' -- optional
require 'nnname'
It sets the name of the module to name
and return the module.
It returns the first nn.Module whose name is name
in the nn.Container by default. It returns the last module with that specific name when last
is true
.
It returns a table of modules in the nn.Container whose name is name
.
model = nn.Sequential():setName('net')
:add(nn.Linear(10, 4):setName('linear'))
:add(nn.ReLU(true):setName('relu_1'))
:add(nn.Linear(4, 1):setName('linear'))
:add(nn.Sigmoid(true):setName('Sigmoid'))
relu = model:find('relu_1') -- get the module with name 'relu_1'
linears = model:findAll('linear') -- get a table of modules with name 'linear'