Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multilabel image classification with sparse labels in TensorFlow?

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.

like image 815
ZCDEV Avatar asked Sep 26 '16 07:09

ZCDEV


People also ask

How do I add a label to an image dataset for classification?

To add the label to multiple images, select the images, and then click the + button on the left hand side. Users can easily add new labels which were not previously in the dataset. To do this, type in the name of the desired label in the left hand side text box, and then click on add.

What is the difference between multiclass and Multilabel classification?

Multiclass classification makes the assumption that each sample is assigned to one and only one label: a fruit can be either an apple or a pear but not both at the same time. Multilabel classification assigns to each sample a set of target labels.


1 Answers

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.

like image 108
tachyontraveler Avatar answered Oct 19 '22 04:10

tachyontraveler