View source on GitHub |
Computes the categorical hinge loss between y_true
& y_pred
.
tf.keras.losses.categorical_hinge(
y_true, y_pred
)
Formula:
loss = maximum(neg - pos + 1, 0)
where neg=maximum((1-y_true)*y_pred)
and pos=sum(y_true*y_pred)
Returns | |
---|---|
Categorical hinge loss values with shape = [batch_size, d0, .. dN-1] .
|
Example:
y_true = np.random.randint(0, 3, size=(2,))
y_true = np.eye(np.max(y_true) + 1)[y_true]
y_pred = np.random.random(size=(2, 3))
loss = keras.losses.categorical_hinge(y_true, y_pred)