コード例 #1
0
    def test_static_graph_functional(self):
        '''test_static_graph_functional'''

        for use_cuda in ([False, True]
                         if core.is_compiled_with_cuda() else [False]):
            place = paddle.CUDAPlace(0) if use_cuda else paddle.CPUPlace()

            paddle.enable_static()
            x_1 = paddle.fluid.data(
                name="x", shape=[2, 1, 12, 12], dtype="float64")
            x_2 = paddle.fluid.data(
                name="x2", shape=[2, 12, 12, 1], dtype="float64")
            out_1 = F.pixel_unshuffle(x_1, 3)
            out_2 = F.pixel_unshuffle(x_2, 3, "NHWC")

            exe = paddle.static.Executor(place=place)
            res_1 = exe.run(fluid.default_main_program(),
                            feed={"x": self.x_1_np},
                            fetch_list=out_1,
                            use_prune=True)

            res_2 = exe.run(fluid.default_main_program(),
                            feed={"x2": self.x_2_np},
                            fetch_list=out_2,
                            use_prune=True)

            assert np.allclose(res_1, self.out_1_np)
            assert np.allclose(res_2, self.out_2_np)
コード例 #2
0
    def run_dygraph(self, down_factor, data_format):
        '''run_dygraph'''

        n, c, h, w = 2, 1, 12, 12

        if data_format == "NCHW":
            shape = [n, c, h, w]
        if data_format == "NHWC":
            shape = [n, h, w, c]

        x = np.random.random(shape).astype("float64")

        npresult = pixel_unshuffle_np(x, down_factor, data_format)

        for use_cuda in ([False, True]
                         if core.is_compiled_with_cuda() else [False]):
            place = paddle.CUDAPlace(0) if use_cuda else paddle.CPUPlace()

            paddle.disable_static(place=place)

            pixel_unshuffle = paddle.nn.PixelUnshuffle(
                down_factor, data_format=data_format)
            result = pixel_unshuffle(paddle.to_tensor(x))

            self.assertTrue(np.allclose(result.numpy(), npresult))

            result_functional = F.pixel_unshuffle(
                paddle.to_tensor(x), 3, data_format)
            self.assertTrue(np.allclose(result_functional.numpy(), npresult))

            pixel_unshuffle_str = 'downscale_factor={}'.format(down_factor)
            if data_format != 'NCHW':
                pixel_unshuffle_str += ', data_format={}'.format(data_format)
            self.assertEqual(pixel_unshuffle.extra_repr(), pixel_unshuffle_str)
コード例 #3
0
 def error_data_format():
     with paddle.fluid.dygraph.guard():
         x = np.random.random([2, 1, 12, 12]).astype("float64")
         pixel_unshuffle = F.pixel_unshuffle(
             paddle.to_tensor(x), 3, "WOW")
コード例 #4
0
 def error_downscale_factor_2():
     with paddle.fluid.dygraph.guard():
         x = np.random.random([2, 1, 12, 12]).astype("float64")
         pixel_unshuffle = F.pixel_unshuffle(paddle.to_tensor(x), -1)
コード例 #5
0
 def error_input():
     with paddle.fluid.dygraph.guard():
         x = np.random.random([4, 12, 12]).astype("float64")
         pixel_unshuffle = F.pixel_unshuffle(paddle.to_tensor(x), 2)