@@ -37,18 +37,18 @@ def set_data(self):
37
37
self .outputs = {'Out' : self .out_data }
38
38
39
39
def init_test_case (self ):
40
- self .batch_size = 1
40
+ self .batch_size = 3
41
41
self .channels = 3
42
42
self .height = 8
43
43
self .width = 6
44
44
45
45
# n, c, h, w
46
46
self .x_dim = (self .batch_size , self .channels , self .height , self .width )
47
47
48
- self .spatial_scale = 1.0 / 1 .0
48
+ self .spatial_scale = 1.0 / 2 .0
49
49
self .pooled_height = 2
50
50
self .pooled_width = 2
51
- self .sampling_ratio = 2
51
+ self .sampling_ratio = - 1
52
52
53
53
self .x = np .random .random (self .x_dim ).astype ('float32' )
54
54
@@ -57,7 +57,7 @@ def pre_calc(self, x_i, roi_xmin, roi_ymin, roi_bin_grid_h, roi_bin_grid_w,
57
57
count = roi_bin_grid_h * roi_bin_grid_w
58
58
bilinear_pos = np .zeros (
59
59
[self .channels , self .pooled_height , self .pooled_width , count , 4 ],
60
- np .int32 )
60
+ np .float32 )
61
61
bilinear_w = np .zeros (
62
62
[self .pooled_height , self .pooled_width , count , 4 ], np .float32 )
63
63
for ph in range (self .pooled_width ):
@@ -85,7 +85,7 @@ def pre_calc(self, x_i, roi_xmin, roi_ymin, roi_bin_grid_h, roi_bin_grid_w,
85
85
if x_low >= self .width - 1 :
86
86
x = x_high = x_low = self .width - 1
87
87
else :
88
- x_high = x_low = self . width - 1
88
+ x_high = x_low + 1
89
89
ly = y - y_low
90
90
lx = x - x_low
91
91
hy = 1 - ly
@@ -107,8 +107,9 @@ def pre_calc(self, x_i, roi_xmin, roi_ymin, roi_bin_grid_h, roi_bin_grid_w,
107
107
return bilinear_pos , bilinear_w
108
108
109
109
def calc_roi_align (self ):
110
- self .out_data = np .zeros ((self .rois_num , self .channels ,
111
- self .pooled_height , self .pooled_width ))
110
+ self .out_data = np .zeros (
111
+ (self .rois_num , self .channels , self .pooled_height ,
112
+ self .pooled_width )).astype ('float32' )
112
113
113
114
for i in range (self .rois_num ):
114
115
roi = self .rois [i ]
@@ -118,14 +119,14 @@ def calc_roi_align(self):
118
119
roi_ymin = roi [2 ] * self .spatial_scale
119
120
roi_xmax = roi [3 ] * self .spatial_scale
120
121
roi_ymax = roi [4 ] * self .spatial_scale
121
- roi_width = int ( max (roi_xmax - roi_xmin , 1 ) )
122
- roi_height = int ( max (roi_ymax - roi_ymin , 1 ) )
122
+ roi_width = max (roi_xmax - roi_xmin , 1 )
123
+ roi_height = max (roi_ymax - roi_ymin , 1 )
123
124
bin_size_h = float (roi_height ) / float (self .pooled_height )
124
125
bin_size_w = float (roi_width ) / float (self .pooled_width )
125
126
roi_bin_grid_h = self .sampling_ratio if self .sampling_ratio > 0 else \
126
- math .ceil (roi_height / pooled_height )
127
+ math .ceil (roi_height / self . pooled_height )
127
128
roi_bin_grid_w = self .sampling_ratio if self .sampling_ratio > 0 else \
128
- math .ceil (roi_width / pooled_width )
129
+ math .ceil (roi_width / self . pooled_width )
129
130
count = int (roi_bin_grid_h * roi_bin_grid_w )
130
131
pre_size = count * self .pooled_width * self .pooled_height
131
132
bilinear_pos , bilinear_w = self .pre_calc (x_i , roi_xmin , roi_ymin ,
@@ -139,7 +140,7 @@ def calc_roi_align(self):
139
140
140
141
def make_rois (self ):
141
142
rois = []
142
- self .rois_lod = [[0 ]]
143
+ self .rois_lod = [[]]
143
144
for bno in range (self .batch_size ):
144
145
self .rois_lod [0 ].append (bno + 1 )
145
146
for i in range (bno + 1 ):
@@ -166,4 +167,4 @@ def test_check_output(self):
166
167
self .check_output ()
167
168
168
169
def test_check_grad (self ):
169
- self .check_grad (['X' ], 'Out' )
170
+ self .check_grad (['X' ], 'Out' , max_relative_error = 0.005 )
0 commit comments