TuSimple / mx-maskrcnn

An MXNet implementation of Mask R-CNN
Apache License 2.0
1.76k stars 550 forks source link

The output of ROIPoolingAlign layer #102

Closed Mendel1 closed 6 years ago

Mendel1 commented 6 years ago

I'm trying to figure out how all these code run.But some problem occurs when I run a test based on ROIAlign layer.Test code is like below.

import os, sys
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import numpy as np
import mxnet as mx
import random

data = mx.symbol.Variable(name='data')
rois = mx.symbol.Variable(name='rois')
#test = mx.symbol.ROIPooling(data=data, rois=rois, pooled_size=(2, 2), spatial_scale=1)
'''
[[0,1],
 [10,11]]
'''
test = mx.symbol.ROIAlign(data=data, rois=rois, pooled_size=(2, 2), spatial_scale=1)

h, w = 10, 10
x = [[[[i*w+j for j in range(w)] for i in range(h)]]]
for x_ in x[0][0]:
    print(x_)

y = [[0,0,0,1,1]]
o=[[0.0]]

x = mx.nd.array(x, dtype='float32',ctx=mx.gpu(1))
y = mx.nd.array(y, dtype='float32',ctx=mx.gpu(1))
ex = test.bind(ctx=mx.gpu(1), args={'data':x, 'rois':y})
y = ex.forward()
print(y)
print(y[0].asnumpy())

In my thought,it should output

[[0.66,1.66],
 [10.66,11.66]]

But it output

[[7.33,8.33],
[17.33,18.33]]

Could you tell me some points in this layer? Thanks very much.

Zehaos commented 6 years ago

Hi, @Mendel1 I run the test code, and the ouput is as below:

python roi_align_test.py 
[0, 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, 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, 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, 76, 77, 78, 79]
[80, 81, 82, 83, 84, 85, 86, 87, 88, 89]
[90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
[
[[[[ 3.66666651  4.16666651]
   [ 8.66666603  9.16666698]]]]
<NDArray 1x1x2x2 @gpu(0)>]

Please refer to maskrcnn_iccv2017_tutorial_kaiminghe.pdf page 24.

Mendel1 commented 6 years ago

@Zehaos Thank you very much.I found I had changed something and didn't comment it before running. I'll read the tutorial.