Last active
August 17, 2016 18:48
-
-
Save chaonan99/5ebe87198a069fc4562b8336ce0c2312 to your computer and use it in GitHub Desktop.
View structure of a torch checkpoint (table)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
[Description] View structure of a torch checkpoint (table) | |
[Author] chaonan99 | |
[Date] 08/17/2016 | |
[Contact] [email protected] | |
--]] | |
require 'torch' | |
require 'nn' | |
require 'nngraph' | |
require 'cunn' | |
require 'cudnn' | |
require 'cutorch' | |
-- local imports | |
require 'misc.LanguageModel' | |
cmd = torch.CmdLine() | |
cmd:text() | |
cmd:text('View .t7 model structure') | |
cmd:option('-model','checkpoints/model_idcoco_pre.t7','path to the torch model to view') | |
cmd:option('-max_depth',1,'max depth to view') | |
cmd:option('-max_num',20,"view at most x number of items") | |
local opt = cmd:parse(arg) | |
local function viewKey(ta, spaces, depth, num) | |
local count = 0 -- Is there a better way? | |
for _ in pairs(ta) do count = count + 1 end | |
local n = 1 | |
for k,v in pairs(ta) do | |
io.write(spaces..tostring(k)) | |
n = n + 1 | |
if type(v) == 'table' and depth < opt.max_depth then | |
io.write("\n") | |
viewKey(v,spaces.." ",depth + 1,num) | |
elseif type(v) == 'table' then io.write("\n") | |
elseif type(v) ~= 'userdata' then io.write(" :"..tostring(v).."\n") | |
elseif v.type then io.write(" :"..v:type().."\n") end | |
if n > num then io.write(spaces.."... (total "..tostring(count).." items)\n") break end | |
end | |
end | |
loader = torch.load(opt.model) | |
viewKey(loader, "", 0, opt.max_num) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment