diff --git a/python/paddle/fluid/tests/unittests/test_batch_norm_op.py b/python/paddle/fluid/tests/unittests/test_batch_norm_op.py index c2a6c468e5c8f184e6e74a98151d6c008ba997d4..02171db3fca75a7fbd655771818f2e21fea52f5d 100644 --- a/python/paddle/fluid/tests/unittests/test_batch_norm_op.py +++ b/python/paddle/fluid/tests/unittests/test_batch_norm_op.py @@ -768,6 +768,10 @@ class TestBatchNormOpError(unittest.TestCase): ) self.assertRaises(TypeError, paddle.static.nn.batch_norm, x2) + # the first dimension of input for batch_norm must between [2d, 5d]. + x3 = paddle.static.data("", shape=[0], dtype="float32") + self.assertRaises(ValueError, paddle.static.nn.batch_norm, x3) + class TestDygraphBatchNormAPIError(unittest.TestCase): def test_errors(self): diff --git a/python/paddle/fluid/tests/unittests/test_fold_op.py b/python/paddle/fluid/tests/unittests/test_fold_op.py index 1f3193fa1fd49470678a69a7143eba43dc49b878..a86161cc4502308c61dbde77ffff9c608b40e6ff 100644 --- a/python/paddle/fluid/tests/unittests/test_fold_op.py +++ b/python/paddle/fluid/tests/unittests/test_fold_op.py @@ -179,7 +179,7 @@ class TestFoldOpError(unittest.TestCase): with program_guard(Program(), Program()): def test_input_shape(): - # input_shpae must be 3-D + # input_shape must be 3-D x = paddle.randn(shape=[2, 3, 6, 7], dtype="float32") out = fold(x, output_sizes=[2, 3], kernel_sizes=[2, 2]) diff --git a/python/paddle/static/nn/common.py b/python/paddle/static/nn/common.py index 3b40153cbb797d76ace0e3a950e533f2b36d6648..c43385a8e91409f90535ba428d1b83b9715ec503 100644 --- a/python/paddle/static/nn/common.py +++ b/python/paddle/static/nn/common.py @@ -2731,6 +2731,12 @@ def batch_norm( dtype = core.VarDesc.VarType.FP32 input_shape = input.shape + if len(input.shape) < 2 or len(input.shape) > 5: + raise ValueError( + 'expected 2D or 3D or 4D or 5D input (got {}D input, input shape is: {})'.format( + len(input.shape), input_shape + ) + ) if data_layout == 'NCHW': channel_num = input_shape[1] else: