Skip to content
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

Running main.lua for training gives reshape function exception #35

Open
rohanchabra opened this issue Jul 21, 2017 · 7 comments
Open

Running main.lua for training gives reshape function exception #35

rohanchabra opened this issue Jul 21, 2017 · 7 comments

Comments

@rohanchabra
Copy link

rohanchabra commented Jul 21, 2017

I am able to run the test set correctly. But training gives me such error. The images are in the correct folder. What might be the problem?

./main.lua kitti slow -a train_trkitti
slow -a train_tr
luajit: ./main.lua:378: inconsistent tensor size, expected tensor [389 x 1 x 350 x 1242] and src [] to have the same number of elements, but got 169098300 and 0 elements respectively at /home/rohan140290/torch/pkg/torch/lib/TH/generic/THTensorCopy.c:86
stack traceback:
[C]: in function 'reshape'
./main.lua:378: in function 'fromfile'
./main.lua:428: in main chunk
[C]: at 0x00405d50

It seems like torch is not able to parse the file correctly.
x = torch.FloatTensor(torch.FloatStorage(fname)) :- Seems to have issues.

I instead tried to do this:-

for i = 1,#dim do
s = s * dim[i]
end

x = torch.FloatTensor(torch.FloatStorage(s))
torch.DiskFile(fname,'r'):binary():readFloat(x:storage())

This seems to work for me.

@strivejin
Copy link

I change the code just like you do :
"I instead tried to do this:-

for i = 1,#dim do
s = s * dim[i]
end

x = torch.FloatTensor(torch.FloatStorage(s))
torch.DiskFile(fname,'r'):binary():readFloat(x:storage())"
but it still don't work ,do you know why?

kitti slow -a train_tr
luajit: ./main.lua:369: attempt to perform arithmetic on global 's' (a nil value)
stack traceback:
./main.lua:369: in function 'fromfile'
./main.lua:434: in main chunk
[C]: at 0x00405d50

@strivejin
Copy link

@rohanchabra

@ComVisDinh
Copy link

I have the same problem. Do you have a solution for this?

@strivejin
Copy link

you should give s a initial value,like this :

for i = 1,#dim do
s=1
s = s * dim[i]
end

@ComVisDinh

@ComVisDinh
Copy link

It works. Thank you 👍

@sooyeonshin
Copy link

your problem fixed?
I have same issue, so I change the code but still show error message at reshape function.

if type == 'float32' then
for i = 1,#dim do
s = 1
s = s * dim[i]
end
x = torch.FloatTensor(torch.FloatStorage(s))
torch.DiskFile(fname,'r'):binary():readFloat(x:storage())
elseif type == 'int32' then
for i = 1,#dim do
s = 1
s = s * dim[i]
end
x = torch.IntTensor(torch.IntStorage(s))
torch.DiskFile(fname,'r'):binary():readInt(x:storage())

elseif type == 'int64' then
for i = 1,#dim do
s = 1
s = s * dim[i]
end
x = torch.LongTensor(torch.LongStorage(s))
torch.DiskFile(fname,'r'):binary():readLong(x:storage())

else
print(fname, type)
assert(false)
end

x = x:reshape(torch.LongStorage(dim))
return x

-------------------------------------------------------------------------error message-----------------------------------
luajit: ./main.lua:396: inconsistent tensor size, expected tensor [389 x 1 x 350 x 1242] and src [1242] to have the same number of elements, but got 169098300 and 1242 elements respectively at /home/vclab-ubuntu/torch/pkg/torch/lib/TH/generic/THTensorCopy.c:86
stack traceback:
[C]: in function 'reshape'
./main.lua:396: in function 'fromfile'
./main.lua:446: in main chunk
[C]: at 0x00405d50

@ComVisDinh
Copy link

Variable s should be outside of a FOR loop. If it is inside, it always resets to value 1 for each repeat.

if type == 'float32' then
--x = torch.FloatTensor(torch.FloatStorage(fname))

  s=1
  for i = 1,#dim do	 
 s = s * dim[i]
  end

  x = torch.FloatTensor(torch.FloatStorage(s))
  torch.DiskFile(fname,'r'):binary():readFloat(x:storage())

elseif type == 'int32' then
print('inside --------------------- 1 ')
--x = torch.IntTensor(torch.IntStorage(fname))

  s=1
  for i = 1,#dim do	 
 s = s * dim[i]
  end

  x = torch.IntTensor(torch.IntStorage(s))
  torch.DiskFile(fname,'r'):binary():readInt(x:storage())

elseif type == 'int64' then
print('inside --------------------- 3 ')
--x = torch.LongTensor(torch.LongStorage(fname))

  s=1
  for i = 1,#dim do	 
 s = s * dim[i]
  end

  x = torch.LongTensor(torch.LongStorage(s))
  torch.DiskFile(fname,'r'):binary():readLong(x:storage())

else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants