CategoricalCrossentropy

class dragon.vm.tensorflow.keras.losses.CategoricalCrossentropy(
  axis=- 1,
  reduction='mean',
  name=None
)[source]

A criterion to compute the categorical cross entropy with contiguous targets.

The CrossEntropy function is defined as:

\[\text{CrossEntropy}(p_{t}) = -\log(p_{t}) \]

Examples:

criterion = tf.keras.losses.CategoricalCrossentropy()
y_true = tf.constant([[0., 1.], [1., 0.]])
y_pred = tf.constant([[0.5, 0.5], [0.3, 0.7]])
print(criterion(y_true, y_pred))  # 0.8030813

__init__

CategoricalCrossentropy.__init__(
  axis=- 1,
  reduction='mean',
  name=None
)[source]

Create a CategoricalCrossentropy criterion.

Parameters:
  • axis (int, optional, default=-1) – The axis to apply softmax.
  • reduction ({'none', 'sum', 'mean', 'valid'}, optional) – The reduction method.
  • name (str, optional) – The operation name.

Methods

__call__

Loss.__call__(
  y_true,
  y_pred
)[source]

Compute the defined loss function.

Parameters:
Returns:

dragon.Tensor – The loss.