 tensorflow 6 0 Stack Overflow 收藏 评论 • N ：批次中的图像数
• H ：图像的高度
• W ：图像的宽度
• C ：图像的通道数（例如：RGB为3，灰度为1 ...）

### 从NHWC到NCHW

``````perm = 0  # output dimension 0 will be 'N', which was dimension 0 in the input
perm = 3  # output dimension 1 will be 'C', which was dimension 3 in the input
perm = 1  # output dimension 2 will be 'H', which was dimension 1 in the input
perm = 2  # output dimension 3 will be 'W', which was dimension 2 in the input
``````

``````images_nhwc = tf.placeholder(tf.float32, [None, 200, 300, 3])  # input batch
out = tf.transpose(x, [0, 3, 1, 2])
print(out.get_shape())  # the shape of out is [None, 3, 200, 300]
``````

### 从NCHW到NHWC

``````perm = 0  # output dimension 0 will be 'N', which was dimension 0 in the input
perm = 2  # output dimension 1 will be 'H', which was dimension 2 in the input
perm = 3  # output dimension 2 will be 'W', which was dimension 3 in the input
perm = 1  # output dimension 3 will be 'C', which was dimension 1 in the input
``````

``````images_nchw = tf.placeholder(tf.float32, [None, 3, 200, 300])  # input batch
out = tf.transpose(x, [0, 2, 3, 1])
print(out.get_shape())  # the shape of out is [None, 200, 300, 3]
`````` 收藏 评论

• 社区规范
• 提出问题
• 进行投票
• 个人资料
• 优化问题
• 回答问题 关于我们 常见问题 内容许可 联系我们