DepthToSpace 用于 T 类型的张量。
用法
tf.nn.depth_to_space(
input, block_size, data_format='NHWC', name=None
)参数
-
input一个Tensor。 -
block_sizeint即>= 2。空间块的大小,与 Space2Depth 相同。 -
data_format一个可选的string来自:"NHWC", "NCHW", "NCHW_VECT_C"。默认为"NHWC"。 -
name操作的名称(可选)。
返回
-
一个
Tensor。具有与input相同的类型。
将数据从深度重新排列到空间数据块中。这是 SpaceToDepth 的逆向变换。更具体地说,此操作输出输入张量的副本,其中来自 depth 维度的值在空间块中移动到 height 和 width 维度。 attr block_size 指示输入块大小以及数据的移动方式。
- 来自深度的大小为
block_size * block_size的数据块被重新排列为大小为block_size x block_size的非重叠块 - 输出张量的宽度是
input_depth * block_size,而高度是input_height * block_size。 - 输出图像的每个块内的 Y、X 坐标由输入通道索引的高阶分量确定。
- 输入张量的深度必须能被
block_size * block_size整除。
data_format attr 使用以下选项指定输入和输出张量的布局: "NHWC": [ batch, height, width, channels ] "NCHW": [ batch, channels, height, width ] "NCHW_VECT_C": qint8 [ batch, channels / 4, height, width, 4 ]
将操作视为转换 6-D 张量很有用。例如对于data_format = NHWC,输入张量中的每个元素都可以通过 6 个坐标指定,按内存布局重要性递减顺序排列为:n,iY,iX,bY,bX,oC(其中 n=batch index,iX,iY 表示输入图像内的 X 或 Y 坐标,bX,bY 表示输出块内的坐标,oC 表示输出通道)。输出将是转换为以下布局的输入:n,iY,bY,iX,bX,oC
此操作对于调整卷积之间的激活大小(但保留所有数据)很有用,例如而不是池化。它对于训练纯卷积模型也很有用。
例如,给定形状为 [1, 1, 1, 4] 的输入,data_format = "NHWC" 和 block_size = 2:
x = [[[[1, 2, 3, 4]]]]
此操作将输出形状为 [1, 2, 2, 1] 的张量:
[[[[1], [2]],
[[3], [4]]]]
在这里,输入有一个批次 1,每个批次元素的形状为 [1, 1, 4] ,相应的输出将有 2x2 个元素,并且深度为 1 个通道(1 = 4 / (block_size * block_size) )。输出元素形状为 [2, 2, 1] 。
对于深度较大的输入张量,这里的形状为 [1, 1, 1, 12] ,例如
x = [[[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]]]
对于块大小为 2,此操作将返回以下形状的张量 [1, 2, 2, 3]
[[[[1, 2, 3], [4, 5, 6]],
[[7, 8, 9], [10, 11, 12]]]]
同样,对于以下形状 [1 2 2 4] 的输入,块大小为 2:
x = [[[[1, 2, 3, 4],
[5, 6, 7, 8]],
[[9, 10, 11, 12],
[13, 14, 15, 16]]]]
运算符将返回以下形状的张量 [1 4 4 1] :
x = [[[ [1], [2], [5], [6]],
[ [3], [4], [7], [8]],
[ [9], [10], [13], [14]],
[ [11], [12], [15], [16]]]]
相关用法
- Python tf.nn.depthwise_conv2d用法及代码示例
- Python tf.nn.dropout用法及代码示例
- Python tf.nn.dilation2d用法及代码示例
- Python tf.nn.embedding_lookup_sparse用法及代码示例
- Python tf.nn.RNNCellResidualWrapper.set_weights用法及代码示例
- Python tf.nn.gelu用法及代码示例
- Python tf.nn.RNNCellDeviceWrapper.set_weights用法及代码示例
- Python tf.nn.embedding_lookup用法及代码示例
- Python tf.nn.RNNCellDeviceWrapper.get_weights用法及代码示例
- Python tf.nn.local_response_normalization用法及代码示例
- Python tf.nn.scale_regularization_loss用法及代码示例
- Python tf.nn.RNNCellResidualWrapper.add_loss用法及代码示例
- Python tf.nn.max_pool用法及代码示例
- Python tf.nn.RNNCellDropoutWrapper.set_weights用法及代码示例
- Python tf.nn.l2_loss用法及代码示例
- Python tf.nn.log_softmax用法及代码示例
- Python tf.nn.weighted_cross_entropy_with_logits用法及代码示例
- Python tf.nn.ctc_greedy_decoder用法及代码示例
- Python tf.nn.RNNCellResidualWrapper.get_weights用法及代码示例
- Python tf.nn.compute_average_loss用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.nn.depth_to_space。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
