votes up 8

`num_labels` is needed only when `multi_label` is True.

Exception Class:

Raise code

._built = False
    if self.multi_label:
      if num_labels:
        shape = tensor_shape.TensorShape([None, num_labels])
      if num_labels:
        raise ValueError(
            '`num_labels` is needed only when `multi_label` is True.')

  def thresholds(self):
    """The thresholds used for evaluating AUC."""
    return list(self._thresholds)

  def _
😲 Agile task management is now easier than calling a taxi. #Tracklify
🙏 Scream for help to Ukraine
Today, 2nd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 2 votes down

If multi_label is False the num_labels shouldn't be given.

Reproducing the error:

import tensorflow as tf
m = tf.keras.metrics.AUC(num_thresholds=3,num_labels=2)
m.update_state([[0,1], [1,0], [1,0], [0,1]], [[0,1], [0.5,0.5], [0.3,0.7], [1,0.9]])
print( m.result().numpy())

The error output:

ValueError                                Traceback (most recent call last)
<ipython-input-36-9666877749e9> in <module>()
----> 1 m = tf.keras.metrics.AUC(num_thresholds=3,num_labels=2)
      2 m.update_state([0, 0, 1, 1], [0, 0.5, 0.3, 0.9])
      3 print( m.result().numpy())

/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/ in __init__(self, num_thresholds, curve, summation_method, name, dtype, thresholds, multi_label, num_labels, label_weights, from_logits)
   2134       if num_labels:
   2135         raise ValueError(
-> 2136             '`num_labels` is needed only when `multi_label` is True.')
   2137       self._build(None)

ValueError: `num_labels` is needed only when `multi_label` is True.


multi_label is set to False by default. Make sure it is explicitly set to True if num_labels is given.

import tensorflow as tf
m = tf.keras.metrics.AUC(num_thresholds=3,num_labels=2,multi_label=True)
m.update_state([[0,1], [1,0], [1,0], [0,1]], [[0,1], [0.5,0.5], [0.3,0.7], [1,0.9]])
print( m.result().numpy())



Jul 09, 2021 kellemnegasi answer
kellemnegasi 30.0k

Add a possible fix

Please authorize to post fix