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

区别

NHWC

[batch, in_height, in_width, in_channels]

NCHW

[batch, in_channels, in_height, in_width]

转换

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)

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)


你可能感兴趣的:(TensorFlow,TensorFlow,框架)