From 104c82b1b82fe048da41ce9a1700f8acd76eea3c Mon Sep 17 00:00:00 2001 From: huangjun12 <12272008@bjtu.edu.cn> Date: Mon, 26 Jul 2021 07:13:09 +0000 Subject: [PATCH] fix lrn bug when shape=0 --- python/paddle/fluid/tests/unittests/test_lrn_op.py | 6 ++++++ python/paddle/nn/functional/norm.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/python/paddle/fluid/tests/unittests/test_lrn_op.py b/python/paddle/fluid/tests/unittests/test_lrn_op.py index 2b632b2437..5882419698 100644 --- a/python/paddle/fluid/tests/unittests/test_lrn_op.py +++ b/python/paddle/fluid/tests/unittests/test_lrn_op.py @@ -323,6 +323,12 @@ class TestLocalResponseNormFAPIError(unittest.TestCase): self.assertRaises(ValueError, test_dim) + def test_shape(): + x = fluid.data(name='x', shape=[0, 0, 2, 3], dtype="float32") + paddle.nn.functional.local_response_norm(x, size=5) + + self.assertRaises(ValueError, test_shape) + class TestLocalResponseNormCAPI(unittest.TestCase): def setUp(self): diff --git a/python/paddle/nn/functional/norm.py b/python/paddle/nn/functional/norm.py index 863787c00e..c61fafdcb9 100644 --- a/python/paddle/nn/functional/norm.py +++ b/python/paddle/nn/functional/norm.py @@ -487,6 +487,12 @@ def local_response_norm(x, 'Expected 3D or higher dimensionality input, but got {} dimensions'. format(dim)) + for i, size in enumerate(sizes): + if not size > 0: + raise ValueError("Expected every dim's size to be larger than 0, " + "but the size of the {}-th dim is {}".format(i, + size)) + channel_last = True if data_format[-1] == "C" else False from functools import reduce -- GitLab