| by YoungTimes | No comments

TensorFlow:tf.space_to_depth函数通俗解释

函数原型:

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

tf.space_to_depth将Input Tensor的height、weight维度的值移到Output Tensor的depth维度。

通俗的讲,就是实现如下的功能:

Input Tensor: [batch, height, width, channels]

Output Tensor: [batch, height / block_size, width / block_size, channels * block_size * block_size]

应用示例

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

y = tf.space_to_depth(x, 2) # [[[[1, 2, 3, 4]]]]

Input Tensor的shape为[1, 2, 2, 1],Output Tensor的shape为[1, 1, 1, 4]。

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

y = tf.space_to_depth(x, 2)

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

Input Tensor的shape为[1, 4, 4, 1],Output Tensor的shape为[1, 2, 2, 4]。

参考材料

https://www.tensorflow.org/api_docs/python/tf/nn/space_to_depth

除非注明,否则均为[半杯茶的小酒杯]原创文章,转载必须以链接形式标明本文链接

本文链接:http://www.banbeichadexiaojiubei.com/index.php/2020/11/25/tensorflow%ef%bc%9atf-space_to_depth%e5%87%bd%e6%95%b0%e9%80%9a%e4%bf%97%e8%a7%a3%e9%87%8a/