tf.keras.losses.categorical_hinge
Вычисляет категориальную функцию потерь hinge между y_true и y_pred.
tf.keras.losses.categorical_hinge(
y_true, y_pred
)
Формула:
loss = maximum(neg - pos + 1, 0)
где neg=maximum((1-y_true)*y_pred) и pos=sum(y_true*y_pred)
| Аргументы | |
|---|---|
y_true | Эталонные значения. Ожидается, что значения y_true будут иметь тип {-1, +1} или {0, 1} (т. е. тензор с one-hot-кодированием) и форму = [batch_size, d0, .. dN]. |
y_pred | Предсказанные значения с формой = [batch_size, d0, .. dN]. |
| Возвращает | |
|---|---|
Значения категориальной функции потерь hinge с формой = [batch_size, d0, .. dN-1]. |
Пример:
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)
© 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/keras/losses/categorical_hinge