TensorFlow 中带有稀疏标签的多标签图像分类? [英] Multilabel image classification with sparse labels in TensorFlow?
问题描述
我想为 n 个类别执行多标签图像分类任务.我有每个图像的稀疏标签向量,每个标签向量的每个维度目前都以这种方式编码:
I want to perform a multilabel image classification task for n classes. I've got sparse label vectors for each image and each dimension of each label vector is currently encoded in this way:
1.0 ->Label true/图片属于此类
1.0 ->Label true / Image belongs to this class
-1.0 ->Label false/Image 不包含该类.
-1.0 ->Label false / Image does not contain to this class.
0.0 ->缺失值/标签
0.0 ->missing value/label
例如:V= {1.0,-1.0,1.0, 0.0}
E.g.: V= {1.0,-1.0,1.0, 0.0}
对于这个例子 V,模型应该学习,相应的图像应该被分类为第一类和第三类.
For this example V the model should learn, that the corresponding image should be classified in the first and third class.
我目前的问题是如何处理缺失值/标签.我已经搜索了问题并发现了这个问题:tensorflow/skflow#113 在这里找到
My problem is currently how to handle the missing values/labels. I've searched through the issues and found this issue: tensorflow/skflow#113 found here
因此可以使用以下方法进行多标签图像分类:tf.nn.sigmoid_cross_entropy_with_logits(logits,目标,名称=无)
So could do multilable image classification with: tf.nn.sigmoid_cross_entropy_with_logits(logits, targets, name=None)
但是TensorFlow对于sparse softmax有这个误差函数,用于排他分类:tf.nn.sparse_softmax_cross_entropy_with_logits(logits,标签,名称=无)
but TensorFlow has this error function for sparse softmax, which is used for exclusive classification: tf.nn.sparse_softmax_cross_entropy_with_logits(logits, labels, name=None)
那么有没有像稀疏 sigmoid 交叉熵这样的东西?(找不到东西)或任何关于如何处理稀疏标签的多标签分类问题的建议.
So is there something like sparse sigmoid cross entropy? (Couldn't find something) or any suggestions how can I handle my multilabel classification problem with sparse labels.
推荐答案
我使用了 weighted_cross_entropy_with_logits 作为损失函数,其权重为 1s.
I used weighted_cross_entropy_with_logits as the loss function with positive weights for 1s.
就我而言,所有标签都同等重要.但是 0 作为任何标签的值出现的可能性是 1 的十倍.
In my case, all the labels are equally important. But 0 was ten times more likely to be appeared as the value of any label than 1.
所以我通过调用上述损失函数的 pos_weight 参数来衡量所有的 1.我使用了 10 的 pos_weight(= 正值的权重).顺便说一下,我不推荐任何计算 pos_weight 的策略.我认为这将明确取决于手头的数据.
So I weighed all the 1s by calling the pos_weight parameter of the aforementioned loss function. I used a pos_weight (= weight on positive values) of 10. By the way, I do not recommend any strategy to calculate the pos_weight. I think it will depend explicitly on the data in hand.
如果真实标签=1,weighted_cross_entropy = pos_weight * sigmoid_cross_entropy
带 logits 的加权交叉熵与 带 logits 的 Sigmoid 交叉熵相同,除了额外的权重值乘以所有 目标一个正的实际价值,即;1.
Weighted cross entropy with logits is same as the Sigmoid cross entropy with logits, except for the extra weight value multiplied to all the targets with a positive real value i.e.; 1.
理论上,它应该可以完成这项工作.我仍在调整其他参数以优化性能.稍后会更新性能统计数据.
Theoretically, it should do the job. I am still tuning other parameters to optimize the performance. Will update with performance statistics later.
这篇关于TensorFlow 中带有稀疏标签的多标签图像分类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!