hughperkins / pytorch

Python wrappers for torch and lua
BSD 2-Clause "Simplified" License
431 stars 70 forks source link

Path of a lua file not recognized #11

Closed deshraj closed 8 years ago

deshraj commented 8 years ago

Hi,

I am using pytorch in one of my projects and when I give the path of lua file in the following line like this: TorchModel = PyTorchHelpers.load_lua_class('/home/ubuntu/deshraj/grad-cam/sample.lua', 'TorchModel')

Then it shows the following error: PANIC: unprotected error in call to Lua API (module '/home/ubuntu/deshraj/grad-cam/sample' not found: but the file exists there.

@hughperkins Is this not the correct way of giving the path ?

deshraj commented 8 years ago

Seeing https://github.com/hughperkins/pytorch/blob/master/src/PyTorchHelpers.py#L7 , it seems that pytorch doesnot provide support for the location of a file instead of giving the file name directly.

hughperkins commented 8 years ago

Hi Deshraj,

It's a limitation of how the lua loader works. It's similar to how module loading in python works actually: generally you'll need to pip install modules in python, to access them; or else add them to PYTHONPATH, and the same is approximately true in lua (but using things like LUA_PATH instead of PYTHONPATH).

You can see you get the same error from lua directly, eg create:

/tmp/foo.lua

require 'torch'

local Foo = torch.class('Foo')
return Foo

and ~/test.lua :

require '/tmp/foo.lua'

Now run, like:

cd ~
luajit test.lua

Output for me:

(env3) ubuntu@peach:~$ luajit test.lua
luajit: test.lua:1: module '/tmp/foo.lua' not found:
    no field package.preload['/tmp/foo.lua']
    no file '/home/ubuntu/.luarocks/share/lua/5.1//tmp/foo/lua.lua'
    no file '/home/ubuntu/.luarocks/share/lua/5.1//tmp/foo/lua/init.lua'
    no file '/home/ubuntu/torch-cl/install/share/lua/5.1//tmp/foo/lua.lua'
    no file '/home/ubuntu/torch-cl/install/share/lua/5.1//tmp/foo/lua/init.lua'
    no file '/home/ubuntu/git/distro/install/share/lua/5.1//tmp/foo/lua.lua'
    no file '/home/ubuntu/git/distro/install/share/lua/5.1//tmp/foo/lua/init.lua'
    no file './/tmp/foo/lua.lua'
    no file '/home/ubuntu/git/distro/install/share/luajit-2.1.0-beta1//tmp/foo/lua.lua'
    no file '/usr/local/share/lua/5.1//tmp/foo/lua.lua'
    no file '/usr/local/share/lua/5.1//tmp/foo/lua/init.lua'
    no file '/home/ubuntu/torch-cl/install/lib//tmp/foo/lua.so'
    no file '/home/ubuntu/.luarocks/lib/lua/5.1//tmp/foo/lua.so'
    no file '/home/ubuntu/torch-cl/install/lib/lua/5.1//tmp/foo/lua.so'
    no file '/home/ubuntu/git/distro/install/lib//tmp/foo/lua.so'
    no file '/home/ubuntu/git/distro/install/lib/lua/5.1//tmp/foo/lua.so'
    no file './/tmp/foo/lua.so'
    no file '/usr/local/lib/lua/5.1//tmp/foo/lua.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
    no file '/home/ubuntu/torch-cl/install/lib//tmp/foo.so'
    no file '/home/ubuntu/.luarocks/lib/lua/5.1//tmp/foo.so'
    no file '/home/ubuntu/torch-cl/install/lib/lua/5.1//tmp/foo.so'
    no file '/home/ubuntu/git/distro/install/lib//tmp/foo.so'
    no file '/home/ubuntu/git/distro/install/lib/lua/5.1//tmp/foo.so'
    no file './/tmp/foo.so'
    no file '/usr/local/lib/lua/5.1//tmp/foo.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
    [C]: in function 'require'
    test.lua:1: in main chunk
    [C]: at 0x00405d50
deshraj commented 8 years ago

Ah I see. Thanks for informing @hughperkins .