From 77134300fb91ab7c587d5b45fc50fa55674d16f1 Mon Sep 17 00:00:00 2001 From: wangguanzhong Date: Wed, 22 Sep 2021 10:31:32 +0800 Subject: [PATCH] add dilation check for conv (#35838) --- paddle/fluid/operators/conv_op.cc | 9 +++++++++ python/paddle/fluid/tests/unittests/test_conv1d_layer.py | 1 + 2 files changed, 10 insertions(+) diff --git a/paddle/fluid/operators/conv_op.cc b/paddle/fluid/operators/conv_op.cc index 4cd20e6ecd..1610705c46 100644 --- a/paddle/fluid/operators/conv_op.cc +++ b/paddle/fluid/operators/conv_op.cc @@ -50,6 +50,15 @@ std::vector ConvOp::ComputeOutputShape( ctx->Attrs().Get("padding_algorithm"); int groups = ctx->Attrs().Get("groups"); std::vector dilations = ctx->Attrs().Get>("dilations"); + int dilation_size = dilations.size(); + for (int i = 0; i < dilation_size; ++i) { + PADDLE_ENFORCE_GT( + dilations[i], 0, + platform::errors::InvalidArgument( + "The dilation of Op(Conv) should be larget than 0, but received " + "dilation is %d.", + dilations[i])); + } const std::string data_format = ctx->Attrs().Get("data_format"); // MKL-DNN Kernels are using NCHW order of dims description diff --git a/python/paddle/fluid/tests/unittests/test_conv1d_layer.py b/python/paddle/fluid/tests/unittests/test_conv1d_layer.py index fc0a64b18a..715579c332 100644 --- a/python/paddle/fluid/tests/unittests/test_conv1d_layer.py +++ b/python/paddle/fluid/tests/unittests/test_conv1d_layer.py @@ -204,6 +204,7 @@ def add_error_cases(suite): suite.addTest( Conv1DErrorTestCase( methodName='runTest', padding=[1, 2, 3, 4, 5])) + suite.addTest(Conv1DErrorTestCase(methodName='runTest', dilation=-10)) def load_tests(loader, standard_tests, pattern): -- GitLab