diff options
author | Determinant <ted.sybil@gmail.com> | 2016-02-16 17:04:44 +0800 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2016-02-16 17:04:44 +0800 |
commit | 7dee5871f8f67a78ee704c9efd5d4708e8a27740 (patch) | |
tree | 19d672ba48d4805f3fe7e5c8ba47936dd8a2225c /nerv/layer/init.lua | |
parent | 9e7171e2da3e4edba303f5c2bdaef416fb62e81a (diff) |
improve parameter auto-detection
Diffstat (limited to 'nerv/layer/init.lua')
-rw-r--r-- | nerv/layer/init.lua | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/nerv/layer/init.lua b/nerv/layer/init.lua index 23606e1..86ea9cf 100644 --- a/nerv/layer/init.lua +++ b/nerv/layer/init.lua @@ -70,22 +70,32 @@ function Layer:get_dim() return self.dim_in, self.dim_out end -function Layer:find_param(pid, l_conf, gconf, p_type, p_dim) - if l_conf[pid] ~= nil then - nerv.info("Param [%s] of layer [%s] found in layer_conf.", pid, self.id) - return l_conf[pid] +function Layer:find_param(pid_list, lconf, gconf, p_type, p_dim, target_pid) + if type(pid_list) == "string" then + pid_list = {pid_list} end - local pid_g = self.id .. '_' .. pid --global identifier - local pr = l_conf.pr - local p - if pr ~= nil and pr:has_param(pid_g) == true then - nerv.info("Param [%s] of layer [%s] found in layer_conf.paramRepo.", pid, self.id) - p = pr:get_param(pid_g) - return p + pid_list_str = table.tostring(pid_list) + for i, pid in ipairs(pid_list) do + if lconf[pid] ~= nil then + nerv.info("param [%s] of layer [%s] found in `layer_conf`.", pid, self.id) + return lconf[pid] + end + local pid_g = self.id .. '_' .. pid --global identifier + local pr = lconf.pr + local p + if pr ~= nil and pr:has_param(pid_g) == true then + nerv.info("param [%s] of layer [%s] found in `layer_conf.pr`.", pid_list_str, self.id) + p = pr:get_param(pid_g) + return p + end end - nerv.info("Param [%s] of layer [%s] is not found in layer_conf or layer_conf.paramRepo, switch to auto-generate.", pid, self.id) + nerv.info("param [%s] of layer [%s] is not found in `layer_conf` or `layer_conf.pr`, " .. + "switch to auto-generate.", pid_list_str, self.id) p = p_type(pid_g, gconf) p.trans = gconf.cumat_type(unpack(p_dim)) + if type(gconf.param_random) ~= "function" then + nerv.error("a param generate function is needed") + end p.trans:generate(gconf.param_random) return p end |