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]]]

  TensorFlow的图像NCHW与NHWC