tensorflow: (data_format) NHWC、NCHW 区别与转换

来源:互联网 发布:蚁族淘宝店营业额 编辑:程序博客网 时间:2024/06/04 01:09

区别

NHWC

[batch, in_height, in_width, in_channels]

NCHW

[batch, in_channels, in_height, in_width]

转换

NHWC –> NCHW:

import tensorflow as tfx = tf.reshape(tf.range(24), [1, 3, 4, 2])out = tf.transpose(x, [0, 3, 1, 2])print x.shapeprint out.shape
(1, 3, 4, 2)(1, 2, 3, 4)

NCHW –> NHWC:

import tensorflow as tfx = tf.reshape(tf.range(24), [1, 2, 3, 4])out = tf.transpose(x, [0, 2, 3, 1])print x.shapeprint out.shape
(1, 2, 3, 4)(1, 3, 4, 2)