szagoruyko / imagine-nn

IMAGINE torch neural network routines
Other
109 stars 35 forks source link

ROIPooling layer with v2 gives me wrong output #36

Closed lim0606 closed 8 years ago

lim0606 commented 8 years ago

Hi, this is Jaehyun Lim.

I tried to test ROIPooling layer with simple custom code, and the ROIPooling layer with v2 gave me wrong outputs.

Here is the code I ran;

local inn = require 'inn'

local n_images = 2
local sz = torch.Tensor{2, 5, 5}
local input_image = torch.CudaTensor(n_images, sz[1], sz[2], sz[3]):copy(torch.linspace(1, n_images * sz[1] * sz[2] * sz[3], n_images * sz[1] * sz[2] * sz[3]):reshape(n_images, sz[1], sz[2], sz[3]))

print(input_image)

local n_rois = 2
local rois=torch.CudaTensor(n_rois,5)
for i=1,n_rois do
  idx=torch.randperm(n_images)[1]
  y=torch.randperm(sz[3])[{{1,2}}]:sort()
  x=torch.randperm(sz[2])[{{1,2}}]:sort()
  rois[{i,{}}] = torch.Tensor({idx,x[1],y[1],x[2],y[2]})
  --rois[{i,{}}] = torch.Tensor({idx,1,1,sz[3],sz[2]})
end

print(rois)

local model = inn.ROIPooling(3,3)
model:cuda()

local output = model:forward({input_image, rois})
print(output)

model.v2 = false
local output = model:forward({input_image, rois})
print(output)

and I got

input_image = 
(1,1,.,.) = 
    1    2    3    4    5
    6    7    8    9   10
   11   12   13   14   15
   16   17   18   19   20
   21   22   23   24   25

(2,1,.,.) = 
   51   52   53   54   55
   56   57   58   59   60
   61   62   63   64   65
   66   67   68   69   70
   71   72   73   74   75

(1,2,.,.) = 
   26   27   28   29   30
   31   32   33   34   35
   36   37   38   39   40
   41   42   43   44   45
   46   47   48   49   50

(2,2,.,.) = 
   76   77   78   79   80
   81   82   83   84   85
   86   87   88   89   90
   91   92   93   94   95
   96   97   98   99  100
[torch.CudaTensor of size 2x2x5x5]

rois = 
1  1  1  4  5
2  1  2  3  4
[torch.CudaTensor of size 2x5]

output via v2 = 
(1,1,.,.) = 
   1   2   3
  11  12  13
  16  17  18

(2,1,.,.) = 
  56   0  57
   0   0   0
  61   0  62

(1,2,.,.) = 
  26  27  28
  36  37  38
  41  42  43

(2,2,.,.) = 
  81   0  82
   0   0   0
  86   0  87
[torch.CudaTensor of size 2x2x3x3]

output via v1 = 
(1,1,.,.) = 
   7   8   9
  17  18  19
  22  23  24

(2,1,.,.) = 
  56  57  58
  61  62  63
  66  67  68

(1,2,.,.) = 
  32  33  34
  42  43  44
  47  48  49

(2,2,.,.) = 
  81  82  83
  86  87  88
  91  92  93
[torch.CudaTensor of size 2x2x3x3]

I'm using lua 5.2 instead of luajit 2.1 because of memory issues related to luajit.

I can use v1, but I'd like to know there was any mistake on my usage or a sort of things.

I would appreciate if anyone help me to solve this issue.

Thanks

Best regards,

Jaehyun

lim0606 commented 8 years ago

I think this happens when I tries to run with lua 5.2 instead of luajit 2.1

szagoruyko commented 8 years ago

@lim0606 did you run tests in luajit and lua5.2 https://github.com/szagoruyko/imagine-nn/blob/master/test/test_jacobian.lua ?

lim0606 commented 8 years ago

@szagoruyko

Yes, I did. I wanted to run object detection codes, requiring an abject consuming quite big memery. Because of memory limitation in luajit, i tried to run torch with lua 5.2.

Jaehyun