Skip to content

Commit

Permalink
fix converage, test=develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tink2123 committed Aug 26, 2021
1 parent 192d039 commit fca6240
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions python/paddle/fluid/tests/unittests/test_unpool_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ def data_format_error():
MaxPool2D = F.maxunpool2d(
data, indices, kernel_size=2, stride=2, data_format="NHWC")

def data_outputsize_error():
data = paddle.randint(shape=[1, 1, 3, 3])
indices = paddle.reshape(paddle.arange(4, 40), shape[1, 1, 3, 4])
MaxPool2D = F.maxunpool2d(
data,
indices,
kernel_size=2,
stride=2,
output_size=[5, 6, 7, 8])

def data_outputsize_error2():
data = paddle.randint(shape=[1, 1, 3, 3])
indices = paddle.reshape(paddle.arange(4, 40), shape[1, 1, 3, 4])
MaxPool2D = F.maxunpool2d(
data, indices, kernel_size=2, stride=2, output_size=[100, 100])

self.assertRaises(ValueError, indices_size_error)
self.assertRaises(ValueError, indices_value_error)
self.assertRaises(ValueError, data_format_error)
Expand Down Expand Up @@ -220,6 +236,36 @@ def test_case(self):
self.assertTrue(np.allclose(out_pp.numpy(), expect_res))


class TestUnpoolOpAPI_dy3(unittest.TestCase):
def test_case(self):
import paddle
import paddle.nn.functional as F
import paddle.fluid.core as core
import paddle.fluid as fluid
import numpy as np

if core.is_compiled_with_cuda():
place = core.CUDAPlace(0)
else:
place = core.CPUPlace()
with fluid.dygraph.guard(place):
input_data = np.array([[[[1, 2, 3, 4], [5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]]]]).astype("float32")
input_x = paddle.to_tensor(input_data)
Pool2d = paddle.nn.MaxPool2D(
kernel_size=2, stride=2, return_mask=True)
UnPool = paddle.nn.MaxUnPool2D(kernel_size=2, stride=2)

output, indices = Pool2d(input_x)
out_pp = UnPool(output, indices)
output_np = output.numpy()
indices_np = indices.numpy()
expect_res =unpool2dmax_forward_naive(output_np, indices_np, [2,2], \
[2,2], [0,0], [5,5]).astype("float64")
self.assertTrue(np.allclose(out_pp.numpy(), expect_res))


class TestUnpoolOpAPI_st(unittest.TestCase):
def test_case(self):
import paddle
Expand Down

0 comments on commit fca6240

Please sign in to comment.