# TensorFlow：tf.space_to_depth函数

## tf.space_to_depth 函数

``````space_to_depth(
input,
block_size,
name=None,
data_format='NHWC'
)``````

T型张量的SpaceToDepth.

• 不重叠的block_size乘block size大小的块,在每个位置重新排列成深度.
• 输出张量的深度是block_size * block_size * input_depth.
• 输入的每个块内的Y、X坐标成为输出通道索引的高阶分量.
• 输入张量的高度和宽度必须能被block_size整除.

data_formatATTR用以下选项指定输入和输出张量的布局：“NHWC”：[ batch, height, width, channels ]；“NCHW”：[ batch, channels, height, width ]；“NCHW_VECT_C”：qint8 [ batch, channels / 4, height, width, channels % 4 ]

``````x = [[[[1], [2]],
[[3], [4]]]]``````

``[[[[1, 2, 3, 4]]]]``

``````x = [[[[1, 2, 3], [4, 5, 6]],
[[7, 8, 9], [10, 11, 12]]]]``````

``[[[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]]]``

``````x = [[[[1],   [2],  [5],  [6]],
[[3],   [4],  [7],  [8]],
[[9],  [10], [13],  [14]],
[[11], [12], [15],  [16]]]]``````

``````x = [[[[1, 2, 3, 4],
[5, 6, 7, 8]],
[[9, 10, 11, 12],
[13, 14, 15, 16]]]]``````

### 函数参数

• input：一个Tensor.
• block_size：一个>=2的int,表示空间块的大小.
• data_format：可选的string,来自："NHWC", "NCHW", "NCHW_VECT_C"；默认为"NHWC".
• name：操作的名称(可选).

### 函数返回

tf.space_to_depth函数返回Tensor,它与input具有相同的类型.

App下载