jzbontar / mc-cnn

Stereo Matching by Training a Convolutional Neural Network to Compare Image Patches
BSD 2-Clause "Simplified" License
706 stars 232 forks source link

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

Open rohanchabra opened 7 years ago

rohanchabra commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

@rohanchabra

ComVisDinh commented 6 years ago

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

strivejin commented 6 years ago

you should give s a initial value,like this :

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

@ComVisDinh

ComVisDinh commented 6 years ago

It works. Thank you :+1:

sooyeonshin commented 6 years ago

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 commented 6 years ago

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