-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
convert torch 7 model and get an error :AttributeError: type object 'torch.cuda.FloatStorage' has no attribute 'from_buffer' #8
Comments
Where did you download the vgg.t7? You can try check the size of the vgg.t7 and convert torch.cuda.FloatStorage to torch.FloatStorage before using it. vgg model from https://github.com/jcjohnson/cnn-benchmarks has been tested, you can use this version. |
@clcarwin I got the same error. I try to use this library to convert a standalone training model (from my experiments; not vgg). So is that mean I cannot use this library to convert torch.cuda.FloatStorage? |
@johnny5550822 convert GPU to CPU model first.
|
Got it. Thanks! |
Thanks ;) worked for resnet152 from https://github.com/facebook/fb.resnet.torch |
@johnny5550822 do you get the problem " 'torch.FloatTensor' object has no attribute 'output' ",how should I do? |
@heyalqh did not get this problem. Can you share the screenshot of the code and error? |
Does this mean that I cannot use the model on the GPU after conversion? When I do
When I put my data on the GPU I end up with this error instead:
|
when I try to convert the following torch net to pytorch, require 'torch' function buildModel_MeanPool_RNN(nFltrs1,nFltrs2,nFltrs3,nPersonsTrain) local nFilters = {nFltrs1,nFltrs2,nFltrs3} local filtsize = {5,5,5} -- remember this adds padding to ALL SIDES of the image local cnn = nn.Sequential() local ninputChannels = 5 ninputChannels = nFilters[1] ninputChannels = nFilters[2] local nFullyConnected = nFilters[3]108 cnn:add(nn.Reshape(1,nFullyConnected)) local h2h = nn.Sequential() local r1 = nn.Recurrent( local rnn1 = nn.Sequencer( Combined_CNN_RNN_1 = nn.Sequential() local r2 = nn.Recurrent( local rnn2 = nn.Sequencer( Combined_CNN_RNN_2 = nn.Sequential() -- Combined_CNN_RNN_2 = Combined_CNN_RNN_1:clone('weight','bias','gradWeight','gradBias') local mlp2 = nn.ParallelTable() local mlp3 = nn.ConcatTable() local mlp4 = nn.ParallelTable() -- used to predict the identity of each person -- identification local mlp7 = nn.Sequential() local mlp5 = nn.ParallelTable() local fullModel = nn.Sequential() local crit = nn.SuperCriterion() return fullModel, crit, Combined_CNN_RNN_1, cnn fullModel, crit, Combined_CNN_RNN_1, cnn = buildModel_MeanPool_RNN(16,32,32,150) But it is not working: |
@clcarwin , when i try to convert the model to use float tensors (the original model was trained on GPUs and CUDA tensors is not usable in the code), I get this error:
I'm doing this via the command line 'th', is there any package that is missing and needs to be 'required' for the float tensor conversion? |
@stalagmite7, I have the same problem. Did you ever solve this? Thanks. |
@stalagmite7 @huntkao I am having the same issue! Did either of you end up solving this issue? Thanks a lot! |
No, @huntkao and @Spandan-Madan . I finally ended up not going down this route because it was so buggy |
@clcarwin |
In my specific case, this is what happened:-
lua uses tables for all data arrays pretty much. So the only way to find
out if the object is a model itself or a table containing model and other
things is to look inside the table and see what it contains. In my case,
the table object was a list of tables and one of the tables inside it was
the model. So, I indexed inside to the right element. And then converted
that model to CPU using model = model:float() and it worked perfectly.
I know it sounds silly, but give it a shot. You never know you might have
the same problem as me!
…On Sat, Aug 18, 2018 at 6:10 PM, dmortem ***@***.***> wrote:
@clcarwin <https://github.com/clcarwin>
Hi, I have SyntaxError on the line "m = m:float()". How to solve it?
Thanks a lot!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AU8Xo45ExiBYx1z0Y8ItlYXr2WTROPgGks5uSLsDgaJpZM4NjX48>
.
|
@dmortem Hi, I have the same error with you, do you overcome it and how? |
@LaiPiXiong Hi, I solved it by put codes into a lua file, not python. |
@dmortem Thanks, do you change torch to pytorch successfully? I met error as @stalagmite7. And I try to download xnornet.py but it still show error "string m=m:float() attempt to call method 'float' (a nil value) ". |
@LaiPiXiong After I configuring torch environment, I put three sentences in a lua file, and execute it. The model has been converted successfully. And whether you can use this model in Pytorch depends on the original torch model since some torch structures cannot be used in Pytorch, so maybe we still cannot use the converted model. |
@dmortem I can't convert it right. Does "convert_torch.py" also based on torch? |
@LaiPiXiong I'm sorry, I didn't convert the model successfully, and my error is "torch.utils.serialization.read_lua_file.T7ReaderException: unknown type id 436207616. The file may be corrupted.". This error is because my model has some different layers which are absent in torch.legacy. |
@dmortem I can't convert model in GPU to CPU version. Do you install luarocks before torch? |
@dmortem Hi, I convert torch model to pytorch successfully. I use 'import 'cudnn'' before "m = torch.load(model-name)". I learn this from rwightman/pytorch-planet-amazon#1 |
@LaiPiXiong It's rather
as it is in lua. |
Oh, I see, thanks. |
@johnny5550822 |
Somebody resolved the problem ? |
I have the same issue. Anyone help me please ! |
I am trying to convert this model driveLink from this repo repoLink but it gives the error |
I am trying to use this way to convert the model to cpu but torch.load gives this types of error |
wangjian@lhtserver-2:~/wj$ python convert_torch.py -m vgg.t7
Traceback (most recent call last):
File "convert_torch.py", line 286, in
torch_to_pytorch(args.model,args.output)
File "convert_torch.py", line 233, in torch_to_pytorch
model = load_lua(t7_filename,unknown_classes=True)
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 599, in load_lua
return reader.read()
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 584, in read
return self.read_object()
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 514, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 537, in read_object
return reader_registry[cls_name](self, version)
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 242, in read_nn_class
attributes = reader.read()
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 586, in read
return self.read_table()
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 514, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 563, in read_table
v = self.read()
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 586, in read
return self.read_table()
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 514, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 563, in read_table
v = self.read()
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 584, in read
return self.read_object()
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 514, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 539, in read_object
return TorchObject(cls_name, self.read())
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 586, in read
return self.read_table()
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 514, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 563, in read_table
v = self.read()
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 584, in read
return self.read_object()
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 514, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 537, in read_object
return reader_registry[cls_name](self, version)
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 146, in read_tensor
storage = reader.read()
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 584, in read
return self.read_object()
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 514, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 537, in read_object
return reader_registry[cls_name](self, version)
File "/usr/local/anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 165, in read_storage
return python_class.from_buffer(reader.f.read(size), 'native')
AttributeError: type object 'torch.cuda.FloatStorage' has no attribute 'from_buffer'
The text was updated successfully, but these errors were encountered: