tensorflow icon indicating copy to clipboard operation
tensorflow copied to clipboard

Multilabel image classification with sparse labels?

Open 2ori opened this issue 10 years ago • 6 comments

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: https://github.com/tensorflow/skflow/issues/113

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.

2ori avatar Sep 23 '16 09:09 2ori

Thanks for the question @zorancupic!

We primarily use github issues to track bugs and installation problems. This is a question better suited for StackOverflow. Please ask it there and tag it with the tensorflow tag. Thanks!

tatatodd avatar Oct 04 '16 01:10 tatatodd

@tatatodd But what about feature requests? It seems to me that @zorancupic is asking for a cost functional tf.nn.sparse_sigmoid_cross_entropy_with_logits(logits, labels, name=None) analogously to the already provided ``tf.nn.sparse_softmax_cross_entropy_with_logits(logits, labels, name=None)`.

FlorianWilhelm avatar Oct 04 '16 14:10 FlorianWilhelm

@tatatodd I asked this question on Stackoverflow and didn't get the answer, that this cost function is provided in TensorFlow. But like @FlorianWilhelm mentioned, this would be a good Feature Request. Sparse labels and the multilabel image classification task often occur.

Here is the link to the StackOverflow question: http://stackoverflow.com/questions/39697216/multilabel-image-classification-with-sparse-labels-in-tensorflow/39737057?noredirect=1#comment66817206_39737057

2ori avatar Oct 04 '16 14:10 2ori

@zorancupic @FlorianWilhelm My apologies, I missed the feature request for adding a tf.nn.sparse_sigmoid_cross_entropy_with_logits function.

We definitely welcome pull requests for new functionality!

tatatodd avatar Oct 04 '16 19:10 tatatodd

So looking at this issue and the documentation of tf.nn.sparse_softmax_cross_entropy_with_logits, again I think there might be some confusion here about the word "sparse" here. This function is actually only a shortcut for a one-hot encoding and applying tf.nn.softmax_cross_entropy_with_logits afterwards as explained here. I think @zorancupic understanding and also mine was that "sparse" allows handling of missing labels. Since this is not the case, a method like tf.nn.sparse_sigmoid_cross_entropy_with_logits makes no sense at all I guess.

Regarding the problem of missing labels, I think one could easily solve the problem by applying one of TensorFlow's loss functions that has a weight parameter, e.g. tf.contrib.losses.log_loss. Using a binary vector as weight that is 0 for missing values and 1 for known labels should do the trick.

FlorianWilhelm avatar Oct 05 '16 19:10 FlorianWilhelm

Automatically closing due to lack of recent activity. Since this issue is old at this point, please reopen the issue if it still occurs when tried with the latest version of Tensorflow. Thank you.

itsmeolivia avatar Jun 16 '17 23:06 itsmeolivia