NHWC&NCHW简介
NHWC & NCHW是两种参数呈现的表达方式。在如何表示一组彩色图片的问题上,不同的DL框架有不同的表达。
NHWC&NCHW转换
1、NHWC → NCHW
import tensorflow as tf
x = tf.reshape(tf.range(24), [1, 3, 4, 2])
out = tf.transpose(x, [0, 3, 1, 2])
print(x.shape)
print(out.shape)
(1, 3, 4, 2)
(1, 2, 3, 4)
2、NCHW → NHWC
import tensorflow as tf
x = tf.reshape(tf.range(24), [1, 2, 3, 4])
out = tf.transpose(x, [0, 2, 3, 1])
print(x.shape)
print(out.shape)
(1, 2, 3, 4)
(1, 3, 4, 2)