- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
将张量从 NHWC 格式转换为 NCHW 格式(反之亦然)的最佳方法是什么?
是否有专门执行此操作的操作,或者我需要使用拆分/连接类型操作的某种组合?
最佳答案
您需要做的就是将维度从 NHWC 排列到 NCHW(或相反)。
每个字母的含义可能有助于理解:
图像形状为(N, H, W, C)
,我们希望输出的形状为(N, C, H, W)
。因此,我们需要应用 tf.transpose
以及精心选择的排列 perm
。
The returned tensor's dimension
i
will correspond to the input dimensionperm[i]
perm[0] = 0 # output dimension 0 will be 'N', which was dimension 0 in the input
perm[1] = 3 # output dimension 1 will be 'C', which was dimension 3 in the input
perm[2] = 1 # output dimension 2 will be 'H', which was dimension 1 in the input
perm[3] = 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(images_nhwc, [0, 3, 1, 2])
print(out.get_shape()) # the shape of out is [None, 3, 200, 300]
<小时/>
图像形状为(N, C, H, W)
,我们希望输出的形状为(N, H, W, C)
。因此,我们需要应用 tf.transpose
以及精心选择的排列 perm
。
The returned tensor's dimension
i
will correspond to the input dimensionperm[i]
perm[0] = 0 # output dimension 0 will be 'N', which was dimension 0 in the input
perm[1] = 2 # output dimension 1 will be 'H', which was dimension 2 in the input
perm[2] = 3 # output dimension 2 will be 'W', which was dimension 3 in the input
perm[3] = 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(images_nchw, [0, 2, 3, 1])
print(out.get_shape()) # the shape of out is [None, 200, 300, 3]
关于tensorflow - 在 TensorFlow 中在 NHWC 和 NCHW 之间转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37689423/
我正尝试在调制上执行此示例笔记本 https://github.com/radioML/examples/blob/master/modulation_recognition/RML2016.10a_
我在 GPU 上训练了我的 NCHW 模型并保存了最佳状态。 我现在想对 CPU 进行推断,它显然只支持 NHWC(我得到了一个错误提及)。 我是否必须使用 NHWC 重新训练我的模型,或者有没有办法
经常在tensorflow代码中看到transpose的实现。我想知道为什么有人会想要将 NHWC 张量转置为 NCHW。请给我一个很好的例子及其背后的原因。 最佳答案 而不是引用文档。您应该阅读 C
我尝试在 SegNet 模型上运行预测,但是当调用预测函数时收到错误。 我也尝试使用 with tf.device('/cpu:0'): 运行预测,但我收到了同样的错误 if __name__ ==
在 pytorch 中,我们需要 NCHW 格式的图像,但我的图像是 NHWC。 将此图像输入 CNN 的程序是什么? (我发现 this solution 建议使用“permute”,但我应该在哪里
将张量从 NHWC 格式转换为 NCHW 格式(反之亦然)的最佳方法是什么? 是否有专门执行此操作的操作,或者我需要使用拆分/连接类型操作的某种组合? 最佳答案 您需要做的就是将维度从 NHWC 排列
所以我正在实现 SIFT,问题是我不知道如何在 OpenCV 中处理 channel 。这是我到目前为止所做的。 #ifndef QUANTIZATION_DATABASE_DATA_READ_H #
The official TensorFlow performance guide指出: Most TensorFlow operations used by a CNN support both N
我目前正在尝试为 OCR 任务训练 CRNN(卷积循环神经网络)。我通常保持默认的数据格式,即 NHWC( channel 最后)。但是由于一些部署限制,我想使用 NCHW( channel 优先)数
我是一名优秀的程序员,十分优秀!