コード例 #1
0
    def test_support_dtypes(self):
        """
        test support types
        """
        for dtype in self.support_dtypes:
            pad = 2
            x = np.random.randint(-255, 255, size=self.shape).astype(dtype)
            expect_res = np.pad(x, [[0, 0], [0, 0], [pad, pad], [pad, pad]])

            x_tensor = to_tensor(x).astype(dtype)
            ret_res = zeropad2d(x_tensor, [pad, pad, pad, pad]).numpy()
            self.assertTrue(np.allclose(expect_res, ret_res))
コード例 #2
0
    def test_support_pad3(self):
        """
        test the type of 'pad' is tuple.
        """
        pad = (1, 2, 3, 4)
        x = np.random.randint(-255, 255, size=self.shape)
        expect_res = np.pad(
            x, [[0, 0], [0, 0], [pad[2], pad[3]], [pad[0], pad[1]]])

        x_tensor = to_tensor(x)
        ret_res = zeropad2d(x_tensor, pad).numpy()
        self.assertTrue(np.allclose(expect_res, ret_res))
コード例 #3
0
    def test_support_pad4(self):
        """
        test the type of 'pad' is paddle.Tensor.
        """
        pad = [1, 2, 3, 4]
        x = np.random.randint(-255, 255, size=self.shape)
        expect_res = np.pad(
            x, [[0, 0], [0, 0], [pad[2], pad[3]], [pad[0], pad[1]]])

        x_tensor = to_tensor(x)
        pad_tensor = to_tensor(pad, dtype='int32')
        ret_res = zeropad2d(x_tensor, pad_tensor).numpy()
        self.assertTrue(np.allclose(expect_res, ret_res))
コード例 #4
0
 def test_layer(self):
     self.assertTrue(
         np.allclose(
             zeropad2d(to_tensor(self.x), self.pad).numpy(),
             self.padLayer(to_tensor(self.x))))