Skip to content

Commit 06b488b

Browse files
committed
update
1 parent 42525b0 commit 06b488b

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

python/paddle/tests/test_ops_roi_pool.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import os
16-
import cv2
17-
import shutil
1815
import unittest
1916
import numpy as np
2017

@@ -60,7 +57,7 @@ def roi_pool_functional(self, output_size):
6057
pool_out = roi_pool(
6158
data, boxes, boxes_num=boxes_num, output_size=output_size)
6259

63-
place = paddle.CUDAPlace(0)
60+
place = paddle.CPUPlace()
6461
exe = paddle.static.Executor(place)
6562

6663
pool_out = exe.run(paddle.static.default_main_program(),
@@ -91,6 +88,22 @@ def test_RoIPool(self):
9188
pool_out = roi_pool_c(data, boxes, boxes_num)
9289
np.testing.assert_equal(pool_out.shape, (3, 256, 4, 3))
9390

91+
def test_value(self, ):
92+
data = np.array([i for i in range(1, 17)]).reshape(1, 1, 4,
93+
4).astype(np.float32)
94+
boxes = np.array(
95+
[[1., 1., 2., 2.], [1.5, 1.5, 3., 3.]]).astype(np.float32)
96+
boxes_num = np.array([2]).astype(np.int32)
97+
output = np.array([[[[11.]]], [[[16.]]]], dtype=np.float32)
98+
99+
data = paddle.to_tensor(data)
100+
boxes = paddle.to_tensor(boxes)
101+
boxes_num = paddle.to_tensor(boxes_num)
102+
103+
roi_pool_c = RoIPool(output_size=1)
104+
pool_out = roi_pool_c(data, boxes, boxes_num)
105+
np.testing.assert_almost_equal(pool_out.numpy(), output)
106+
94107

95108
if __name__ == '__main__':
96109
unittest.main()

python/paddle/vision/ops.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -901,11 +901,7 @@ def decode_jpeg(x, mode='unchanged', name=None):
901901
return out
902902

903903

904-
def roi_pool(input,
905-
boxes,
906-
output_size,
907-
spatial_scale=1.0,
908-
boxes_num=None,
904+
def roi_pool(input, boxes, boxes_num, output_size, spatial_scale=1.0,
909905
name=None):
910906
"""
911907
This operator implements the roi_pooling layer.
@@ -923,9 +919,9 @@ def roi_pool(input,
923919
2D-Tensor or 2D-LoDTensor with the shape of [num_boxes,4], the lod level is 1.
924920
Given as [[x1, y1, x2, y2], ...], (x1, y1) is the top left coordinates,
925921
and (x2, y2) is the bottom right coordinates.
922+
boxes_num (Tensor): The number of RoIs in each image, data type is int32. Default: None
926923
output_size (int or tuple[int, int]): The pooled output size(h, w), data type is int32. If int, h and w are both equal to output_size.
927924
spatial_scale (float, optional): Multiplicative spatial scale factor to translate ROI coords from their input scale to the scale used when pooling. Default: 1.0
928-
boxes_num (Tensor): The number of RoIs in each image. Default: None
929925
name(str, optional): For detailed information, please refer
930926
to :ref:`api_guide_Name`. Usually name is no need to set and
931927
None by default.
@@ -935,6 +931,7 @@ def roi_pool(input,
935931
Examples:
936932
.. code-block:: python
937933
import paddle
934+
from paddle.vision.ops import roi_pool
938935
data = paddle.rand([1, 256, 32, 32])
939936
boxes = paddle.rand([3, 4])
940937
boxes[:, 2] += boxes[:, 0] + 3
@@ -1000,18 +997,18 @@ class RoIPool(Layer):
1000997
Examples:
1001998
.. code-block:: python
1002999
import paddle
1003-
import paddle.nn as nn
1000+
from paddle.vision.ops import RoIPool
10041001
data = paddle.rand([1, 256, 32, 32])
10051002
boxes = paddle.rand([3, 4])
10061003
boxes[:, 2] += boxes[:, 0] + 3
10071004
boxes[:, 3] += boxes[:, 1] + 4
10081005
boxes_num = paddle.to_tensor([3]).astype('int32')
1009-
roi_pool_c = nn.RoIPool(output_size=(4, 3))
1010-
pool_out = roi_pool_c(data, boxes, boxes_num)
1006+
roi_pool = RoIPool(output_size=(4, 3))
1007+
pool_out = roi_pool(data, boxes, boxes_num)
10111008
assert pool_out.shape == [3, 256, 4, 3], ''
10121009
"""
10131010

1014-
def __init__(self, output_size, spatial_scale):
1011+
def __init__(self, output_size, spatial_scale=1.0):
10151012
super(RoIPool, self).__init__()
10161013
self._output_size = output_size
10171014
self._spatial_scale = spatial_scale
@@ -1020,6 +1017,10 @@ def forward(self, input, boxes, boxes_num):
10201017
return roi_pool(
10211018
input=input,
10221019
boxes=boxes,
1020+
boxes_num=boxes_num,
10231021
output_size=self._output_size,
1024-
spatial_scale=self._spatial_scale,
1025-
boxes_num=boxes_num)
1022+
spatial_scale=self._spatial_scale)
1023+
1024+
def extra_repr(self):
1025+
main_str = 'output_size={_output_size}, spatial_scale={_spatial_scale}'
1026+
return main_str.format(**self.__dict__)

0 commit comments

Comments
 (0)