title: Tensorflow weighted vs sigmoid cross-entropy loss
body: <p>I am trying to implement multi-label classification using TensorFlow (i.e., each output pattern can have many active units). The problem has imbalanced classes (i.e., much more zeros than ones in the labels distribution, which makes label patterns very sparse).</p>
  
  <p>The best way to tackle the problem should be to use the <code>tf.nn.weighted_cross_entropy_with_logits</code> function. However, I get this runtime error:</p>
  
  <pre><code>ValueError: Tensor conversion requested dtype uint8 for Tensor with dtype float32
  </code></pre>
  
  <p>I can't understand what is wrong here. As input to the loss function, I pass the labels tensor, the logits tensor, and the positive class weight, which is a constant:</p>
  
  <pre><code>positive_class_weight = 10
  loss = tf.nn.weighted_cross_entropy_with_logits(targets=labels, logits=logits, pos_weight=positive_class_weight)
  </code></pre>
  
  <p>Any hints about how to solve this? If I just pass the same labels and logits tensors to the <code>tf.losses.sigmoid_cross_entropy</code> loss function, everything works well (in the sense that Tensorflow runs properly, but of course following training predictions are always zero).</p>
  
  <p>See related problem <a href="https://stackoverflow.com/questions/39697216/multilabel-image-classification-with-sparse-labels-in-tensorflow/47834138#47834138">here</a>.</p>