Hey,
Is there a way to do this in reverse? Since saving in python pickles the file and they cant be directly read in lua using torch.load . I have existing code base in lua and Ive worked on some data using pytorch and want to go back to the lua code.
Thanks!
@ashkamath you will have to save weights to HDF5 files and load them in lua using torch-hdf5
Hi Hantang,
how did you solve this problem? âAttributeError: type object âFloatStorageâ has no attribute âfrom_bufferââ message.
I am having the same message.
thanks
@sdalaman I am having the same error. Did you manage to find any solutions?
Sorry, I didnât read the thread fully. One of the above comments solves the issue.
âThanks, that solves my problem. Previously I used cudnn.convert(model, nn), but did not use model:float(), so there was still cuda tensor.â
I have a question. Once I got the load_lua() working and load a torch model into pytorch, how can I used it? (because it is not an object like this one: http://pytorch.org/tutorials/beginner/blitz/neural_networks_tutorial.html#sphx-glr-beginner-blitz-neural-networks-tutorial-py)
What I obtain from load_lua() is a nn.Sequential object. How can I use this nn.Sequential object?
@alexis-jacq @apaszke Do you have a way to use nn.Sequential after using the load_lua()? I am not sure how to use the loaded model.
Pretty much what I am asking is how to convert a torch.legacy.nn module into a torch.nn module ?
no there is no automatic way to convert legacy.nn.* to nn.*
Hi
I want to convert the pix2pix Image to Image translation model (https://github.com/phillipi/pix2pix) which is built using nngraph. I tried conversion to both pytorch and caffe.
When I try to convert it to caffe model using torch to caffe tool (https://github.com/facebook/fb-caffe-exts#torch2caffe) I get the error âunknown class nn.gModuleâ.
I also try to load torch model in pytorch by load_lua from torch.utils.serialization where I get similar error.
Since, it seems nngraph is not supported for conversion. Is there a way to convert nngraph model to nn model without the need of rewriting or retraining? Down the line, I want to convert the pix2pix model into various formats like caffe, caffe2, coreML and others to test the performance in mobile environment.
Thanks.
Hi,
Please help. I tried to replicate loading a â.t7â checkpoint model and here is what I got:
Python 2.7.13 |Anaconda 4.4.0 (x86_64)| (default, Dec 20 2016, 23:05:08)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type âhelpâ, âcopyrightâ, âcreditsâ or âlicenseâ for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
import torch
from torch.utils.serialization import load_lua
a = load_lua(âtorch/torch-rnn/cv/checkpoint_1000.t7â)
Traceback (most recent call last):
File ââ, line 1, in
File â/Users/yusuf/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.pyâ, line 599, in load_lua
return reader.read()
File â/Users/yusuf/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.pyâ, line 586, in read
return self.read_table()
File â/Users/yusuf/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.pyâ, line 514, in wrapper
result = fn(self, *args, **kwargs)
File â/Users/yusuf/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.pyâ, line 563, in read_table
v = self.read()
File â/Users/yusuf/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.pyâ, line 584, in read
return self.read_object()
File â/Users/yusuf/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.pyâ, line 514, in wrapper
result = fn(self, *args, **kwargs)
File â/Users/yusuf/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.pyâ, line 543, in read_object
âconstructorâ).format(cls_name))
torch.utils.serialization.read_lua_file.T7ReaderException: donât know how to deserialize Lua class nn.LanguageModel. If you want to ignore this error and load this object as a dict, specify unknown_classes=True in readerâs constructor
hey, I got the same error âkeyError: Torch.CudaTensorâ , have you find a solution? thanks~
@visonpon Is your torch model saved as cuda tensors? In that case save the torch model as CPU tensors and then use load_lua to load in PyTorch.
thanks for your reply. But somtimes i want to use pretrianed model from others and their models are saved as cuda tensor. in this case ,do you have any suggestions?
@visonpon Possible that you can open the pretrained model in torch first, convert to CPU, and save it. So that you can load it in PyTorch?
I am trying to convert these models to PyTorch (GitHub - szagoruyko/cvpr15deepcompare: Code and models for "Learning to Compare Image Patches via Convolutional Neural Networks") however, it always returns this error:
AttributeError: âSpatialConvolutionâ object has no attribute âpadWâ
Whether I use load_lua, or the torch to PyTorch projects listed above, I still get this error. The models are provided in .t7 and .bin format. Is there any other way to load that in PyTorch?
Iâm trying to import a t7 as well, but I get this error.
âT7ReaderException: donât know how to deserialize Lua class nn.DataParallelTable. If you want to ignore this error and load this object as a dict, specify unknown_classes=True in readerâs constructorâ
Any clue how to solve this?
@minsukchang seems the DataParallelTable model is not saved correctly. Do you know how the model was saved? https://github.com/soumith/imagenet-multiGPU.torch/blob/master/util.lua shows how to save a DPT model. Try opening the model in Lua torch and save it properly.
@SelvamArul Thanks, Selvam. I didnât save the model, itâs someone elseâs pretrained model actually. But Iâll try to load in Lua torch as suggested. I was wondering if I was getting the error because PyTorch didnât support DPT, but I guess thatâs not the issue?