赞
踩
目录
通俗易懂些,就是把输入为[batch, height, width, channels]形式的Tensor,其在height和width维的值将移至depth维
- space_to_depth(
- input,
- block_size,
- data_format="NHWC",
- name=None)
input:就是输入的Tensor
block_size:就是块大小,一般≥2
data_format:数据形式,如下表,默认“NHWC”
NHWC | [ batch, height, width, channels ] |
NCHW | [ batch, channels, height, width ] |
NCHW_VECT_C | qint8 [ batch, channels / 4, height, width, 4 ] |
name:名字
*输出张量的深度是block_size * block_size * input_depth
一共三种Tensor:
(1)输入大小为:[1, 2, 2, 1]
- test_tensor_1 = [[[[1], [2]],
- [[3], [4]]]]
输出大小:[1, 1, 1, 4]
[[[[1 2 3 4]]]]
(2)输入大小为:[1, 2, 2, 3]
- test_tensor_2 = [[[[1, 2, 3], [4, 5, 6]],
- [[7, 8, 9], [10, 11, 12]]]]
输出大小:[1, 1, 1, 12]
[[[[ 1 2 3 4 5 6 7 8 9 10 11 12]]]]
(3)输入大小为:[1, 4, 4, 1]
- test_tensor_3 = [[[[1], [2], [5], [6]],
- [[3], [4], [7], [8]],
- [[9], [10], [13], [14]],
- [[11], [12], [15], [16]]]]
输出大小:[1, 2, 2, 4]
- [[[[ 1 2 3 4]
- [ 5 6 7 8]]
-
- [[ 9 10 11 12]
- [13 14 15 16]]]]
test_space_to_depth.py
- import tensorflow as tf
- import os
- os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
-
- test_tensor_1 = tf.placeholder('float32', [1, 2, 2, 1], name='test_tensor_1')
- test_tensor_1 = [[[[1], [2]],
- [[3], [4]]]]
- test_tensor_1 = tf.space_to_depth(test_tensor_1, 2)
-
- test_tensor_2 = tf.placeholder('float32', [1, 2, 2, 3], name='test_tensor_1')
- test_tensor_2 = [[[[1, 2, 3], [4, 5, 6]],
- [[7, 8, 9], [10, 11, 12]]]]
- test_tensor_2 = tf.space_to_depth(test_tensor_2, 2)
-
- test_tensor_3 = tf.placeholder('float32', [1, 4, 4, 1], name='test_tensor_1')
- test_tensor_3 = [[[[1], [2], [5], [6]],
- [[3], [4], [7], [8]],
- [[9], [10], [13], [14]],
- [[11], [12], [15], [16]]]]
- test_tensor_3 = tf.space_to_depth(test_tensor_3, 2)
-
- sess = tf.Session()
- print(test_tensor_1)
- print(sess.run(test_tensor_1))
-
- print(test_tensor_2)
- print(sess.run(test_tensor_2))
-
- print(test_tensor_3)
- print(sess.run(test_tensor_3))
结果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。