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 error of deform_conv2d #49962

Merged
merged 1 commit into from
Jan 30, 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
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