TensorFlow的图像NCHW与NHWC

import tensorflow as tf
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
with tf.Session() as sess:
a = tf.reshape(x, [2, 2, 3])
a = sess.run(a)
print(a)
print("----------------------------")
b = tf.reshape(a,[3,2,2])
b = sess.run(b)
print(b)
print("-----------------------------")
c = tf.transpose(b,[1,2,0])
c = sess.run(c)
print(c)
结果:
[[[ 1 2 3]
[ 4 5 6]]
[[ 7 8 9]
[10 11 12]]]
----------------------------
[[[ 1 2]
[ 3 4]]
[[ 5 6]
[ 7 8]]
[[ 9 10]
[11 12]]]
-----------------------------
[[[ 1 5 9]
[ 2 6 10]]
[[ 3 7 11]
[ 4 8 12]]]

多思考也是一种努力,做出正确的分析和选择,因为我们的时间和精力都有限,所以把时间花在更有价值的地方。

浙公网安备 33010602011771号