View source on GitHub
|
Computes the Generalized Cross Entropy loss between y_true & y_pred.
Inherits From: Loss
tf.keras.losses.CategoricalGeneralizedCrossEntropy(
q=0.5,
reduction='sum_over_batch_size',
name='categorical_generalized_cross_entropy',
dtype=None
)
Generalized Cross Entropy (GCE) is a noise-robust loss function that provides better robustness against noisy labels than standard cross entropy. It generalizes both cross entropy and mean absolute error through the parameter q, where values closer to 1 make the loss more robust to noisy labels.
Formula:
loss = (1 - p**q) / q
where p is the predicted probability for the true class and q
is the noise parameter.
Args | |
|---|---|
q
|
Float in range (0, 1). It is the noise parameter.
Controls the behavior of the loss:
|
reduction
|
Type of reduction to apply to the loss. In almost all cases
this should be "sum_over_batch_size". Supported options are
"sum", "sum_over_batch_size", "mean",
"mean_with_sample_weight" or None. "sum" sums the loss,
"sum_over_batch_size" and "mean" sum the loss and divide by the
sample size, and "mean_with_sample_weight" sums the loss and
divides by the sum of the sample weights. "none" and None
perform no aggregation. Defaults to "sum_over_batch_size".
|
name
|
Optional name for the loss instance. |
dtype
|
The dtype of the loss's computations. Defaults to None, which
means using keras.backend.floatx(). keras.backend.floatx() is a
"float32" unless set to different value
(via keras.backend.set_floatx()). If a keras.DTypePolicy is
provided, then the compute_dtype will be utilized.
|
Example:
y_true = np.array([0, 1, 0, 1])
y_pred = np.array([[0.7, 0.3], [0.2, 0.8], [0.6, 0.4], [0.4, 0.6]])
keras.losses.CategoricalGeneralizedCrossEntropy()(y_true, y_pred)
References | |
|---|---|
|
Attributes | |
|---|---|
dtype
|
|
Methods
call
call(
y_true, y_pred
)
from_config
@classmethodfrom_config( config )
get_config
get_config()
__call__
__call__(
y_true, y_pred, sample_weight=None
)
Call self as a function.
View source on GitHub