Skip to content

Commit

Permalink
fix the div 0 error of deform_conv2d (#49962)
Browse files Browse the repository at this point in the history
  • Loading branch information
Liyulingyue authored Jan 30, 2023
1 parent 0111a35 commit 2d59aa0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions python/paddle/fluid/tests/unittests/test_deformable_conv_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,23 @@ def test_invalid_filter():

self.assertRaises(ValueError, test_invalid_filter)

def test_invalid_groups():
paddle.enable_static()
input = paddle.static.data(
name='input_groups', shape=[1, 1, 1, 1], dtype='float32'
)
offset = paddle.static.data(
name='offset_groups', shape=[1, 1], dtype='float32'
)
mask = paddle.static.data(
name='mask_groups', shape=[1], dtype='float32'
)
paddle.static.nn.deform_conv2d(
input, offset, mask, 1, 1, padding=1, groups=0
)

self.assertRaises(ValueError, test_invalid_groups)


class TestDeformConv2DAPI(unittest.TestCase):
def test_api(self):
Expand Down
2 changes: 2 additions & 0 deletions python/paddle/static/nn/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2255,6 +2255,8 @@ def deformable_conv(
if groups is None:
num_filter_channels = num_channels
else:
if groups == 0:
raise ValueError("groups should not be 0.")
if num_channels % groups != 0:
raise ValueError("num_channels must be divisible by groups.")
num_filter_channels = num_channels // groups
Expand Down

0 comments on commit 2d59aa0

Please sign in to comment.