tensorflow - 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 中使用索引?
解决方案
推荐阅读
- loops - 有没有办法在 DB2 中添加一个 while 循环?
- javascript - 如何使用对象的括号表示法和属性名称的字符串向对象添加属性?
- python - 带单引号且不带转义字符的 JSON 对象
- node.js - MySQL 查询不会超过承诺链中的某个点
- regex - 301 重定向到 URL 中带有 # 的域
- scikit-learn - 在 svm.scv() 中同时使用“class_weight”和“c”参数会发生什么?
- postgresql - PostgreSQL Generate_Series() 插入未完成
- c++ - 调试 curl 未处理的异常
- c# - 对项目源进行列表插入时,组合框项目未更新
- java - 如何检查超过和低于某些预定限制的值