Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the div 0 errors in psroi_pool #49965

Merged
merged 3 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions python/paddle/fluid/tests/unittests/test_psroi_pool_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,22 @@ def test_channel_error():
self.assertRaises(ValueError, test_channel_error)


class TestPSROIPoolZeroDivError(unittest.TestCase):
def setUp(self):
paddle.disable_static()
self.x = paddle.uniform([2, 490, 28, 28], dtype='float32')
self.boxes = paddle.to_tensor(
[[1, 5, 8, 10], [4, 2, 6, 7], [12, 12, 19, 21]], dtype='float32'
)
self.boxes_num = paddle.to_tensor([1, 2], dtype='int32')

def test_errors(self):
def test_zero_div_error():
paddle.vision.ops.psroi_pool(self.x, self.boxes, self.boxes_num, 0)

self.assertRaises(ValueError, test_zero_div_error)


class TestPSROIPoolStaticAPI(unittest.TestCase):
def setUp(self):
paddle.enable_static()
Expand Down
2 changes: 2 additions & 0 deletions python/paddle/vision/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,8 @@ def psroi_pool(x, boxes, boxes_num, output_size, spatial_scale=1.0, name=None):
output_size = (output_size, output_size)
pooled_height, pooled_width = output_size
assert len(x.shape) == 4, "Input features with shape should be (N, C, H, W)"
if pooled_height * pooled_width == 0:
raise ValueError('output_size should not contain 0.')
output_channels = int(x.shape[1] / (pooled_height * pooled_width))
if in_dygraph_mode():
return _C_ops.psroi_pool(
Expand Down