(self, dev)
| 3381 | self.upsample_helper(gpu_dev) |
| 3382 | |
| 3383 | def depth_space_helper(self, dev): |
| 3384 | # (1, 8, 2, 3) input tensor |
| 3385 | X = np.array( |
| 3386 | [[[[0., 1., 2.], [3., 4., 5.]], [[9., 10., 11.], [12., 13., 14.]], |
| 3387 | [[18., 19., 20.], [21., 22., 23.]], |
| 3388 | [[27., 28., 29.], [30., 31., 32.]], |
| 3389 | [[36., 37., 38.], [39., 40., 41.]], |
| 3390 | [[45., 46., 47.], [48., 49., 50.]], |
| 3391 | [[54., 55., 56.], [57., 58., 59.]], |
| 3392 | [[63., 64., 65.], [66., 67., 68.]]]], |
| 3393 | dtype=np.float32) |
| 3394 | x = tensor.from_numpy(X) |
| 3395 | x.to_device(dev) |
| 3396 | |
| 3397 | # (1, 2, 4, 6) output tensor |
| 3398 | y_t = np.array( |
| 3399 | [[[[0., 18., 1., 19., 2., 20.], [36., 54., 37., 55., 38., 56.], |
| 3400 | [3., 21., 4., 22., 5., 23.], [39., 57., 40., 58., 41., 59.]], |
| 3401 | [[9., 27., 10., 28., 11., 29.], [45., 63., 46., 64., 47., 65.], |
| 3402 | [12., 30., 13., 31., 14., 32.], [48., 66., 49., 67., 50., 68.]]] |
| 3403 | ], |
| 3404 | dtype=np.float32) |
| 3405 | dy = tensor.from_numpy(y_t) |
| 3406 | dy.to_device(dev) |
| 3407 | y = autograd.depth_to_space(x, 2, "DCR") |
| 3408 | dx = y.creator.backward(dy.data) |
| 3409 | np.testing.assert_array_almost_equal(tensor.to_numpy(y), y_t) |
| 3410 | np.testing.assert_array_almost_equal(tensor.to_numpy(tensor.from_raw_tensor(dx)), X) |
| 3411 | |
| 3412 | y = autograd.space_to_depth(dy, 2, "DCR") |
| 3413 | dx = y.creator.backward(x.data) |
| 3414 | np.testing.assert_array_almost_equal(tensor.to_numpy(y), X) |
| 3415 | np.testing.assert_array_almost_equal(tensor.to_numpy(tensor.from_raw_tensor(dx)), y_t) |
| 3416 | |
| 3417 | y_t = np.array( |
| 3418 | [[[[0., 9., 1., 10., 2., 11.], [18., 27., 19., 28., 20., 29.], |
| 3419 | [3., 12., 4., 13., 5., 14.], [21., 30., 22., 31., 23., 32.]], |
| 3420 | [[36., 45., 37., 46., 38., 47.], [54., 63., 55., 64., 56., 65.], |
| 3421 | [39., 48., 40., 49., 41., 50.], [57., 66., 58., 67., 59., 68.]]] |
| 3422 | ], |
| 3423 | dtype=np.float32) |
| 3424 | dy = tensor.from_numpy(y_t) |
| 3425 | dy.to_device(dev) |
| 3426 | y = autograd.depth_to_space(x, 2, "CRD") |
| 3427 | dx = y.creator.backward(dy.data) |
| 3428 | np.testing.assert_array_almost_equal(tensor.to_numpy(y), y_t) |
| 3429 | np.testing.assert_array_almost_equal(tensor.to_numpy(tensor.from_raw_tensor(dx)), X) |
| 3430 | |
| 3431 | y = autograd.space_to_depth(dy, 2, "CRD") |
| 3432 | dx = y.creator.backward(x.data) |
| 3433 | np.testing.assert_array_almost_equal(tensor.to_numpy(y), X) |
| 3434 | np.testing.assert_array_almost_equal(tensor.to_numpy(tensor.from_raw_tensor(dx)), y_t) |
| 3435 | |
| 3436 | def test_depth_space_cpu(self): |
| 3437 | self.depth_space_helper(cpu_dev) |
no test coverage detected