{"action":"opened","issue":{"url":"https://api.github.com/repos/imodpasteur/lutorpy/issues/39","repository_url":"https://api.github.com/repos/imodpasteur/lutorpy","labels_url":"https://api.github.com/repos/imodpasteur/lutorpy/issues/39/labels{/name}","comments_url":"https://api.github.com/repos/imodpasteur/lutorpy/issues/39/comments","events_url":"https://api.github.com/repos/imodpasteur/lutorpy/issues/39/events","html_url":"https://github.com/imodpasteur/lutorpy/issues/39","id":206416330,"number":39,"title":"issuse in loading pre-trained model with torch","user":{"login":"danieljf24","id":10017953,"avatar_url":"https://avatars.githubusercontent.com/u/10017953?v=3","gravatar_id":"","url":"https://api.github.com/users/danieljf24","html_url":"https://github.com/danieljf24","followers_url":"https://api.github.com/users/danieljf24/followers","following_url":"https://api.github.com/users/danieljf24/following{/other_user}","gists_url":"https://api.github.com/users/danieljf24/gists{/gist_id}","starred_url":"https://api.github.com/users/danieljf24/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danieljf24/subscriptions","organizations_url":"https://api.github.com/users/danieljf24/orgs","repos_url":"https://api.github.com/users/danieljf24/repos","events_url":"https://api.github.com/users/danieljf24/events{/privacy}","received_events_url":"https://api.github.com/users/danieljf24/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-02-09T06:23:01Z","updated_at":"2017-02-09T06:23:01Z","closed_at":null,"body":"Hello, everayone. I'd like to load a pre-trained torch model using lutorpy, but I failed. Your help will be appreciated.\r\nThe codes are as follows:\r\n\r\nSave the torch model\r\n`require 'nn';\r\n\r\nmlp = nn.Sequential()\r\n\r\nmlp:add(nn.Linear(10, 10))\r\nmlp:add(nn.Tanh())\r\nmlp:add(nn.Linear(10, 10))\r\nmlp:add(nn.Tanh())\r\n\r\nmlp:add(nn.Linear(10, 2))\r\nmlp:add(nn.LogSoftMax())\r\n\r\nprint(mlp)\r\n\r\ninput = torch.Tensor(1,10):copy(torch.range(1, 10))\r\nprint(input)\r\n\r\nout = mlp:forward(input)\r\nprint(out)\r\n\r\n\r\ntorch.save('test.t7', mlp)\r\n`\r\n\r\nLoad the troch model and apply it with lutorpy\r\n`import numpy as np\r\nimport lutorpy as lua\r\n\r\n# load your torch file(for example xx.t7 containing the model and weights)\r\nmodel = torch.load('test.t7')\r\n\r\n# generate your input data with numpy\r\narr = np.array(range(10))\r\n\r\n# convert your numpy array into torch tensor\r\nx = torch.fromNumpyArray(arr)\r\n\r\n# apply model forward method with \"._\" syntax(which is equivalent to \":\" in lua)\r\nyt = model._forward(x)\r\n\r\n# convert to numpy array\r\nyn = yt.asNumpyArray()\r\n\r\nprint yn`\r\n\r\nErrors\r\n`Traceback (most recent call last):\r\n  File \"test.lutorpy.py\", line 5, in <module>\r\n    model = torch.load('test.t7')\r\n  File \"lutorpy/_lupa.pyx\", line 562, in lutorpy._lupa._LuaObject.__call__ (lutorpy/_lupa.c:9459)\r\n  File \"lutorpy/_lupa.pyx\", line 1658, in lutorpy._lupa.call_lua (lutorpy/_lupa.c:25877)\r\n  File \"lutorpy/_lupa.pyx\", line 1667, in lutorpy._lupa.execute_lua_call (lutorpy/_lupa.c:25987)\r\n  File \"lutorpy/_lupa.pyx\", line 1620, in lutorpy._lupa.raise_lua_error (lutorpy/_lupa.c:25297)\r\nlutorpy._lupa.LuaError: ...niel/software/torch/install/share/lua/5.1/torch/File.lua:343: unknown Torch class <nn.Sequential>\r\n`\r\n\r\n"}}
{"actor":{"display_login":"danieljf24"}}