2

I have an imbalanced dataset,and my task is multi-label classification

this is my code for minimizing loss:

logits = inference(input)
xent = tf.nn.sigmoid_cross_entropy_with_logits(
        logits=logits, labels=labels, name='xent')
loss = tf.reduce_mean(xent, name='loss_op')

now.I want to use weighted-loss for my classification,exactly how can I do it? Can I use this link,and replace softmax with sigmoid ?

Point

I have read this link,but my case is not binary classification and in tensorflow_org I think it is for binary classification too.

1 Answers1

2

You could use tf.losses.compute_weighted_loss. I suggest reading the code to see exactly how this function works, but you should be able to do, roughly:

logits = inference(input)
xent = tf.nn.sigmoid_cross_entropy_with_logits(
    logits=logits, labels=labels, name='xent')
weighted_loss = tf.losses.compute_weighted_loss(xent, YOUR_WEIGHTS, name='weighted_loss_op')
matwilso
  • 2,924
  • 3
  • 17
  • 24