bshillingford / python-torchfile

Deserialize Lua torch-serialized objects from Python
BSD 3-Clause "New" or "Revised" License
216 stars 25 forks source link

Give errors with some torch models #7

Closed Ahmed-Mohamed15 closed 7 years ago

Ahmed-Mohamed15 commented 7 years ago

i have tried the mentioned test.t7 files and it works correctly but when i tried it with this model it gives me errors when load it Traceback (most recent call last): File "code.py", line 2, in <module> o = torchfile.load('colornet.t7') File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 415, in load return reader.read_obj() File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 386, in read_obj v = self.read_obj() File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 375, in read_obj obj = torch_readers[className](self, version) File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 201, in reader obj = reader.read_obj() File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 386, in read_obj v = self.read_obj() File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 375, in read_obj obj = torch_readers[className](self, version) File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 201, in reader obj = reader.read_obj() File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 386, in read_obj v = self.read_obj() File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 386, in read_obj v = self.read_obj() File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 375, in read_obj obj = torch_readers[className](self, version) File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 201, in reader obj = reader.read_obj() File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 386, in read_obj v = self.read_obj() File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 386, in read_obj v = self.read_obj() File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 386, in read_obj v = self.read_obj() File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 386, in read_obj v = self.read_obj() File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 385, in read_obj k = self.read_obj() File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 373, in read_obj obj = TorchObject(className, self.read_obj()) File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 405, in read_obj raise T7ReaderException("unknown object") torchfile.T7ReaderException: unknown object Note: the mentioned model works correctly when run it.

bshillingford commented 7 years ago

Are you using any non-built-in nn modules or other torch classes? If so, which?

Ahmed-Mohamed15 commented 7 years ago

All the python code is import torchfile o = torchfile.load('colornet.t7') and the model is depends on nn image && nngraph && Torch7 packages @bshillingford

bshillingford commented 7 years ago

Should be fixed now, try master.

Ahmed-Mohamed15 commented 7 years ago

okey it is fixed now but it gives me another errors when tried to print the model, so what is the problem ? it may be it can't print the wholo model, if it is, so can i see what is the model consists of ? (some thing like help command or a guide ) so that i can access only what i want because i don't know what is the actual code inside it. @bshillingford

o = torchfile.load('colornet.t7') print (o)

The errors Traceback (most recent call last): File "code.py", line 3, in <module> print o File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 181, in __repr__ return "TorchObject(%s, %s)" % (self._typename, repr(self._obj)) File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 181, in __repr__ return "TorchObject(%s, %s)" % (self._typename, repr(self._obj)) File "/usr/local/lib/python2.7/dist-packages/torchfile.py", line 181, in __repr__ return "TorchObject(%s, %s)" % (self._typename, repr(self._obj)) MemoryError

bshillingford commented 7 years ago

You're trying to print the entire model, and you're running out of memory. To see elements, use o.keys() if it's a dict, or dir(o) if it's a torch class instance.

Please keep in mind that this module is simply for reading .t7 files and inspecting them, e.g. if you wanted to inspect a training checkpoint or extract weights as numpy arrays. Thus you're not able to run a forward pass, but of course you could manually copy the weights into a model in the framework of your choice. Consider using the original Lua code if you just want to run the model.

Ahmed-Mohamed15 commented 7 years ago

i want is to access the trained weights of the layers , that's all i try to get. @bshillingford

bshillingford commented 7 years ago

Then use dir and keys as mentioned, as usual in Python.