|
|
|
@ -166,7 +166,11 @@ class TestPadAPI(unittest.TestCase):
|
|
|
|
|
value = 100
|
|
|
|
|
input_data = np.random.rand(*input_shape).astype(np.float32)
|
|
|
|
|
x = paddle.data(name="x", shape=input_shape)
|
|
|
|
|
result = F.pad(x=x, pad=pad, value=value, mode=mode)
|
|
|
|
|
result = F.pad(x=x,
|
|
|
|
|
pad=pad,
|
|
|
|
|
value=value,
|
|
|
|
|
mode=mode,
|
|
|
|
|
data_format="NCDHW")
|
|
|
|
|
exe = Executor(place)
|
|
|
|
|
fetches = exe.run(default_main_program(),
|
|
|
|
|
feed={"x": input_data},
|
|
|
|
@ -666,5 +670,44 @@ class TestPad3dOpError(unittest.TestCase):
|
|
|
|
|
self.assertRaises(Exception, test_reflect_3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestPadDataformatError(unittest.TestCase):
|
|
|
|
|
def test_errors(self):
|
|
|
|
|
def test_ncl():
|
|
|
|
|
paddle.disable_static(paddle.CPUPlace())
|
|
|
|
|
input_shape = (1, 2, 3, 4)
|
|
|
|
|
pad = paddle.to_tensor(np.array([2, 1, 2, 1]).astype('int32'))
|
|
|
|
|
data = np.arange(
|
|
|
|
|
np.prod(input_shape), dtype=np.float64).reshape(input_shape) + 1
|
|
|
|
|
my_pad = nn.ReplicationPad1d(padding=pad, data_format="NCL")
|
|
|
|
|
data = paddle.to_tensor(data)
|
|
|
|
|
result = my_pad(data)
|
|
|
|
|
|
|
|
|
|
def test_nchw():
|
|
|
|
|
paddle.disable_static(paddle.CPUPlace())
|
|
|
|
|
input_shape = (1, 2, 4)
|
|
|
|
|
pad = paddle.to_tensor(np.array([2, 1, 2, 1]).astype('int32'))
|
|
|
|
|
data = np.arange(
|
|
|
|
|
np.prod(input_shape), dtype=np.float64).reshape(input_shape) + 1
|
|
|
|
|
my_pad = nn.ReplicationPad1d(padding=pad, data_format="NCHW")
|
|
|
|
|
data = paddle.to_tensor(data)
|
|
|
|
|
result = my_pad(data)
|
|
|
|
|
|
|
|
|
|
def test_ncdhw():
|
|
|
|
|
paddle.disable_static(paddle.CPUPlace())
|
|
|
|
|
input_shape = (1, 2, 3, 4)
|
|
|
|
|
pad = paddle.to_tensor(np.array([2, 1, 2, 1]).astype('int32'))
|
|
|
|
|
data = np.arange(
|
|
|
|
|
np.prod(input_shape), dtype=np.float64).reshape(input_shape) + 1
|
|
|
|
|
my_pad = nn.ReplicationPad1d(padding=pad, data_format="NCDHW")
|
|
|
|
|
data = paddle.to_tensor(data)
|
|
|
|
|
result = my_pad(data)
|
|
|
|
|
|
|
|
|
|
self.assertRaises(AssertionError, test_ncl)
|
|
|
|
|
|
|
|
|
|
self.assertRaises(AssertionError, test_nchw)
|
|
|
|
|
|
|
|
|
|
self.assertRaises(AssertionError, test_ncdhw)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|
|
|
|
|