diff --git a/paddle/phi/infermeta/unary.cc b/paddle/phi/infermeta/unary.cc index 55e895c6622a62d46aab018c7487d65c82c64d8c..8cea16f770631ee309ba073c4b9d9f989f4c110a 100644 --- a/paddle/phi/infermeta/unary.cc +++ b/paddle/phi/infermeta/unary.cc @@ -2533,6 +2533,10 @@ void PixelShuffleInferMeta(const MetaTensor& x, "Input should be a 4-D tensor of format [N, C, H, W] " "or [N, H, W, C], but got %u.", input_dims.size())); + PADDLE_ENFORCE_NE( + upscale_factor, + 0, + phi::errors::InvalidArgument("upscale_factor should not be 0.")); const bool channel_last = (data_format == "NHWC"); diff --git a/python/paddle/fluid/tests/unittests/test_pixel_shuffle.py b/python/paddle/fluid/tests/unittests/test_pixel_shuffle.py index 196a4ddbd40056b987dad689c785e5d9fd9d0c73..9600f5a872c56a7734826b457f8a6eb5b916cc92 100644 --- a/python/paddle/fluid/tests/unittests/test_pixel_shuffle.py +++ b/python/paddle/fluid/tests/unittests/test_pixel_shuffle.py @@ -227,6 +227,13 @@ class TestPixelShuffleError(unittest.TestCase): self.assertRaises(TypeError, error_upscale_factor) + def error_0_upscale_factor(): + with paddle.fluid.dygraph.guard(): + x = paddle.uniform([1, 1, 1, 1], dtype='float64') + pixel_shuffle = F.pixel_shuffle(x, 0) + + self.assertRaises(ValueError, error_0_upscale_factor) + def error_data_format(): with paddle.fluid.dygraph.guard(): x = np.random.random([2, 9, 4, 4]).astype("float64")