首页 > 解决方案 > TensorFlow 输出:One-Hot 编码与索引

问题描述

我想问一个概念性问题,关于何时使用 one-hot 编码以及何时使用索引来表示 tensorflow 中多类分类问题中的标签。我遇到了关于这些的维度问题,因为我不确定何时使用哪个。

例如,在这个全连接 NN 示例中,one-hot 编码是合适的。(https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/neural_network_raw.py)但在这个 CNN 示例中,索引是正确的。(https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/convolutional_network.py)。

当我在 CNN 示例代码中对标签使用 one-hot 编码时,出现错误:“ValueError: Rank mismatch: Rank of labels (received 2) should equal rank of logits minus 1 (received 2)”。但是当我使用索引作为标签时,没问题。

有人可以解释何时使用单热编码以及何时在 tensorflow 中使用索引?

标签: tensorflowmachine-learning

解决方案


推荐阅读