(self)
| 94 | self.assertAlmostEqual(2.0, _db[0], places=5) |
| 95 | |
| 96 | def test_pooling(self): |
| 97 | x_shape = [2, 1, 3, 3] |
| 98 | x = singa_wrap.Tensor(x_shape) |
| 99 | x.CopyFloatDataFromHostPtr( |
| 100 | [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]) |
| 101 | |
| 102 | y_shape = [2, 1, 2, 2] |
| 103 | dy = singa_wrap.Tensor(y_shape) |
| 104 | dy.CopyFloatDataFromHostPtr([0.1, 0.2, 0.3, 0.4, 0.1, 0.2, 0.3, 0.4]) |
| 105 | |
| 106 | k_dim = [2, 2] |
| 107 | s_dim = [1, 1] |
| 108 | p_dim = [0, 0] |
| 109 | |
| 110 | # max pooling |
| 111 | handle = singa_wrap.PoolingHandle(x, k_dim, s_dim, p_dim, True) |
| 112 | y = singa_wrap.CpuPoolingForward(handle, x) |
| 113 | self.assertListEqual([2, 1, 2, 2], list(y.shape())) |
| 114 | dx = singa_wrap.CpuPoolingBackward(handle, dy, x, y) |
| 115 | self.assertListEqual([2, 1, 3, 3], list(dx.shape())) |
| 116 | |
| 117 | # avg pooling |
| 118 | handle = singa_wrap.PoolingHandle(x, k_dim, s_dim, p_dim, False) |
| 119 | y = singa_wrap.CpuPoolingForward(handle, x) |
| 120 | self.assertListEqual([2, 1, 2, 2], list(y.shape())) |
| 121 | dx = singa_wrap.CpuPoolingBackward(handle, dy, x, y) |
| 122 | self.assertListEqual([2, 1, 3, 3], list(dx.shape())) |
| 123 | |
| 124 | def test_batch_norm(self): |
| 125 | x_shape = [2, 2] |
nothing calls this directly
no test coverage detected