diff --git a/paddle/fluid/operators/pad3d_op.cc b/paddle/fluid/operators/pad3d_op.cc index c2be9ac97ff89b1737944ee6945d34e3ffd63aa9..e84b5a9d9baaeb769d0456929b070243aac0ea45 100644 --- a/paddle/fluid/operators/pad3d_op.cc +++ b/paddle/fluid/operators/pad3d_op.cc @@ -565,13 +565,11 @@ class Pad3dCPUKernel : public framework::OpKernel { " in reflect mode" ", but received depth(%d) and pad_right(%d).", in_width, pads[1])); - } - - if (mode == "circular") { - PADDLE_ENFORCE_NE( - in_depth * in_height * in_width, 0, - platform::errors::InvalidArgument( - "The input tensor size can not be 0 for circular padding mode.")); + } else if (mode == "circular" || mode == "replicate") { + PADDLE_ENFORCE_NE(in_depth * in_height * in_width, 0, + platform::errors::InvalidArgument( + "The input tensor size can not be 0 for circular " + "or replicate padding mode.")); } const int pad_left = pads[0]; diff --git a/paddle/fluid/operators/pad3d_op.cu b/paddle/fluid/operators/pad3d_op.cu index ed936c10755f07c3255f788de9fe62272bccc0ce..f243a78e5578bb4f00c929733ff3ba3dc28d847f 100644 --- a/paddle/fluid/operators/pad3d_op.cu +++ b/paddle/fluid/operators/pad3d_op.cu @@ -618,13 +618,11 @@ class Pad3dCUDAKernel : public framework::OpKernel { " in reflect mode" ", but received depth(%d) and pad_right(%d).", in_width, pads[1])); - } - - if (mode == "circular") { - PADDLE_ENFORCE_NE( - in_depth * in_height * in_width, 0, - platform::errors::InvalidArgument( - "The input tensor size can not be 0 for circular padding mode.")); + } else if (mode == "circular" || mode == "replicate") { + PADDLE_ENFORCE_NE(in_depth * in_height * in_width, 0, + platform::errors::InvalidArgument( + "The input tensor size can not be 0 for circular " + "or replicate padding mode.")); } const int pad_left = pads[0]; diff --git a/python/paddle/fluid/tests/unittests/test_pad3d_op.py b/python/paddle/fluid/tests/unittests/test_pad3d_op.py index 5ec7bdc66fe4959761b60ed1f188668b32fb8b56..7abc314bc1ba01c7abbaa9b57ee7cbf001446935 100644 --- a/python/paddle/fluid/tests/unittests/test_pad3d_op.py +++ b/python/paddle/fluid/tests/unittests/test_pad3d_op.py @@ -732,6 +732,15 @@ class TestPad3dOpError(unittest.TestCase): mode='circular', data_format="NCDHW") + def test_replicate_1(): + input_shape = (1, 2, 0, 4, 5) + data = np.random.rand(*input_shape).astype(np.float32) + x = paddle.to_tensor(data) + y = F.pad(x, + pad=[1, 1, 1, 1, 2, 3], + mode='replicate', + data_format="NCDHW") + paddle.disable_static() for place in self.places: self.assertRaises(ValueError, test_variable) @@ -739,6 +748,7 @@ class TestPad3dOpError(unittest.TestCase): self.assertRaises(Exception, test_reflect_2) self.assertRaises(Exception, test_reflect_3) self.assertRaises(Exception, test_circular_1) + self.assertRaises(Exception, test_replicate_1) paddle.enable_static()