From 91f25ee3f1f3b79c80fc641aaca4ddd92ce0509f Mon Sep 17 00:00:00 2001 From: wangguanzhong Date: Thu, 23 Sep 2021 14:14:28 +0800 Subject: [PATCH] add dilation check for conv (#35894) --- 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 4cd20e6ecd5..1610705c469 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 fc0a64b18a7..715579c332d 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