`num_labels` is needed only when `multi_label` is True.
Package:
keras
52268

Exception Class:
ValueError
Raise code
._built = False
if self.multi_label:
if num_labels:
shape = tf.TensorShape([None, num_labels])
self._build(shape)
else:
if num_labels:
raise ValueError(
'`num_labels` is needed only when `multi_label` is True.')
self._build(None)
@property
def thresholds(self):
"""The thresholds used for evaluating AUC."""
return list(self._thresholds)
def _
🙏 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.
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.
Links to the raise (1)
https://github.com/keras-team/keras/blob/4a978914d2298db2c79baa4012af5ceff4a4e203/keras/metrics.py#L2114See also in the other packages (1)
(✅️ Fixed)
tensorflow/num-labels-is-needed-only-whe
Ways to fix
Summary: when using the AUC (Area under the curve) we have to make sure multi_label
and the num_labels
parameters agree in value. As pointed out in the documentation The number of labels, is used when multi_label
is True.
Code to reproduce the error (Usage with compile()
API method):
import tensorflow as tf
inputs = tf.keras.Input(shape=(3,))
x = tf.keras.layers.Dense(4, activation=tf.nn.relu)(inputs)
outputs = tf.keras.layers.Dense(5, activation=tf.nn.softmax)(x)
model = tf.keras.Model(inputs=inputs, outputs=outputs)
model.compile(
optimizer='adam',
loss='mean_squared_error',
metrics=[
tf.keras.metrics.MeanSquaredError(),
tf.keras.metrics.AUC(multi_label=False,num_labels=3),
]
)
Working (fixed) version of the code:
import tensorflow as tf
inputs = tf.keras.Input(shape=(3,))
x = tf.keras.layers.Dense(4, activation=tf.nn.relu)(inputs)
outputs = tf.keras.layers.Dense(5, activation=tf.nn.softmax)(x)
model = tf.keras.Model(inputs=inputs, outputs=outputs)
# set multi_label to True
model.compile(
optimizer='adam',
loss='mean_squared_error',
metrics=[
tf.keras.metrics.MeanSquaredError(),
tf.keras.metrics.AUC(multi_label=True, num_labels=3),
]
)
For more usage guides checkout the official Keras decumentation here.
Add a possible fix
Please authorize to post fix