def test_GlobalAveragePool4D_2 (self): np_a = np.reshape(self.np_a, (2,1,2,6)) dc_a = dc.reshape(self.dc_a, (2,1,2,6)) spatial_shape = np.ndim(np_a) -2 npr = np.average(np_a, axis=tuple(range(2, spatial_shape + 2))) for _ in range(spatial_shape): npr = np.expand_dims(npr, -1) dcr = dc.global_average_pool(dc_a) np.testing.assert_allclose(npr.flatten(), np.array(dcr.data()).astype(np.float32), rtol=1e-3, atol=1e-3)
def test_GlobalLpPool2D(self): np_a = np.reshape(self.np_a, (4, 6)) dc_a = dc.reshape(self.dc_a, (4, 6)) if (np.ndim(np_a) <= 2): npr = np_a else: spatial_shape = np.ndim(np_a) - 2 npr = np.linalg.norm(np_a, ord=self.p, axis=2) for _ in range(spatial_shape): npr = np.expand_dims(npr, -1) dcr = dc.global_average_pool(dc_a) np.testing.assert_allclose(npr.flatten(), np.array(dcr.data()).astype(np.float32), rtol=1e-3, atol=1e-3)