|
|
|
@ -21,8 +21,8 @@ from op_test import OpTest
|
|
|
|
|
|
|
|
|
|
class TestSpaceToDepthOp(OpTest):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def helper(in_, width, height, channel, batch, stride, forward, out_):
|
|
|
|
|
channel_out = channel // (stride * stride)
|
|
|
|
|
def helper(in_, width, height, channel, batch, blocksize, forward, out_):
|
|
|
|
|
channel_out = channel // (blocksize * blocksize)
|
|
|
|
|
for b in range(batch):
|
|
|
|
|
for k in range(channel):
|
|
|
|
|
for j in range(height):
|
|
|
|
@ -30,10 +30,10 @@ class TestSpaceToDepthOp(OpTest):
|
|
|
|
|
in_index = i + width * (j + height * (k + channel * b))
|
|
|
|
|
channel2 = k % channel_out
|
|
|
|
|
offset = k // channel_out
|
|
|
|
|
width2 = i * stride + offset % stride
|
|
|
|
|
height2 = j * stride + offset // stride
|
|
|
|
|
out_index = width2 + width * stride * (
|
|
|
|
|
height2 + height * stride *
|
|
|
|
|
width2 = i * blocksize + offset % blocksize
|
|
|
|
|
height2 = j * blocksize + offset // blocksize
|
|
|
|
|
out_index = width2 + width * blocksize * (
|
|
|
|
|
height2 + height * blocksize *
|
|
|
|
|
(channel2 + channel_out * b))
|
|
|
|
|
if forward:
|
|
|
|
|
out_[out_index] = in_[in_index]
|
|
|
|
@ -46,10 +46,10 @@ class TestSpaceToDepthOp(OpTest):
|
|
|
|
|
self.op_type = "space_to_depth"
|
|
|
|
|
self.inputs = {"X": self.x}
|
|
|
|
|
self.helper(self.x_1d, self.x.shape[3], self.x.shape[2],
|
|
|
|
|
self.x.shape[1], self.x.shape[0], self.stride, self.forward,
|
|
|
|
|
self.out_1d)
|
|
|
|
|
self.x.shape[1], self.x.shape[0], self.blocksize,
|
|
|
|
|
self.forward, self.out_1d)
|
|
|
|
|
self.out = np.reshape(self.out_1d, self.infered_shape)
|
|
|
|
|
self.attrs = {"stride": self.stride}
|
|
|
|
|
self.attrs = {"blocksize": self.blocksize}
|
|
|
|
|
self.outputs = {"Out": self.out}
|
|
|
|
|
|
|
|
|
|
def init_data(self):
|
|
|
|
@ -57,7 +57,7 @@ class TestSpaceToDepthOp(OpTest):
|
|
|
|
|
self.infered_shape = (32, 48, 3, 3)
|
|
|
|
|
self.one_d_len = 32 * 48 * 3 * 3
|
|
|
|
|
|
|
|
|
|
self.stride = 2
|
|
|
|
|
self.blocksize = 2
|
|
|
|
|
self.x = np.random.random(self.ori_shape).astype('float32')
|
|
|
|
|
self.x_1d = np.reshape(self.x, self.one_d_len)
|
|
|
|
|
self.out = np.zeros(self.infered_shape).astype('float32')
|
|
|
|
@ -81,7 +81,7 @@ class TestSpaceToDepthOpBasic(TestSpaceToDepthOp):
|
|
|
|
|
self.infered_shape = (32, 32, 3, 3)
|
|
|
|
|
self.one_d_len = 32 * 32 * 3 * 3
|
|
|
|
|
|
|
|
|
|
self.stride = 2
|
|
|
|
|
self.blocksize = 2
|
|
|
|
|
self.x = np.random.random(self.ori_shape).astype('float32')
|
|
|
|
|
self.x_1d = np.reshape(self.x, self.one_d_len)
|
|
|
|
|
self.out = np.zeros(self.infered_shape).astype('float32')
|
|
|
|
@ -95,7 +95,7 @@ class TestSpaceToDepthOpDoubleBasic(TestSpaceToDepthOp):
|
|
|
|
|
self.infered_shape = (32, 32, 3, 3)
|
|
|
|
|
self.one_d_len = 32 * 32 * 3 * 3
|
|
|
|
|
|
|
|
|
|
self.stride = 2
|
|
|
|
|
self.blocksize = 2
|
|
|
|
|
self.x = np.random.random(self.ori_shape).astype('float64')
|
|
|
|
|
self.x_1d = np.reshape(self.x, self.one_d_len)
|
|
|
|
|
self.out = np.zeros(self.infered_shape).astype('float64')
|
|
|
|
@ -109,7 +109,7 @@ class TestSpaceToDepthOpWithStride3(TestSpaceToDepthOp):
|
|
|
|
|
self.infered_shape = (32, 81, 2, 2)
|
|
|
|
|
self.one_d_len = 32 * 81 * 2 * 2
|
|
|
|
|
|
|
|
|
|
self.stride = 3
|
|
|
|
|
self.blocksize = 3
|
|
|
|
|
self.x = np.random.random(self.ori_shape).astype('float32')
|
|
|
|
|
self.x_1d = np.reshape(self.x, self.one_d_len)
|
|
|
|
|
self.out = np.zeros(self.infered_shape).astype('float32')
|
|
|
|
@ -123,7 +123,7 @@ class TestSpaceToDepthOpWithNotSquare(TestSpaceToDepthOp):
|
|
|
|
|
self.infered_shape = (32, 81, 3, 2)
|
|
|
|
|
self.one_d_len = 32 * 81 * 3 * 2
|
|
|
|
|
|
|
|
|
|
self.stride = 3
|
|
|
|
|
self.blocksize = 3
|
|
|
|
|
self.x = np.random.random(self.ori_shape).astype('float32')
|
|
|
|
|
self.x_1d = np.reshape(self.x, self.one_d_len)
|
|
|
|
|
self.out = np.zeros(self.infered_shape).astype('float32')
|
|
|
|
|