Multilabel image classification with sparse labels in TensorFlow?

孤街醉人 提交于 2020-01-01 10:16:33

问题


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 / Image belongs to this class

-1.0 ->Label false / Image does not contain to this class.

0.0 ->missing value/label

E.g.: V= {1.0,-1.0,1.0, 0.0}

For this example V the model should learn, that the corresponding image should be classified in the first and third class.

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

So could do multilable image classification with: tf.nn.sigmoid_cross_entropy_with_logits(logits, targets, name=None)

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)

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.


回答1:


I used weighted_cross_entropy_with_logits as the loss function with positive weights for 1s.

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.

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.

if real label = 1, weighted_cross_entropy = pos_weight * sigmoid_cross_entropy

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.




回答2:


First I would like to know what you mean by missing data? What is the difference between miss and false in your case?

Next, I think it is wrong that you represent your data like this. You have unrelated information that you try to represent on the same dimension. (If it was false or true it would work)

What seems to me better is to represent for each of your class a probability if it is good, or is missing or is false.

In your case V = [(1,0,0),(0,0,1),(1,0,0),(0,1,0)]




回答3:


Ok! So your problem is more about how to handle the missing data I think.

So I think you should definitely use tf.sigmoid_cross_entropy_with_logits()

Just change the target for the missing data to 0.5. (0 for false and 1 for true). I never tried this approach but it should let your network learn without biasing it too much.



来源:https://stackoverflow.com/questions/39697216/multilabel-image-classification-with-sparse-labels-in-tensorflow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!