SiaNet/Losses/KullbackLeiblerDivergence.cs
/// <summary>
/// Forwards the inputs and calculate the loss.
/// </summary>
/// <param name="preds">The predicted result.</param>
/// <param name="labels">The true result.</param>
/// <returns></returns>
Forwards the inputs and calculate the loss.
Forwards the inputs and calculate the loss .
public override Tensor Forward(Tensor preds, Tensor labels)
        {
            var y_true = K.Clip(labels, K.Epsilon(), 1);
            var y_pred = K.Clip(preds, K.Epsilon(), 1);
            return K.Sum(y_true * K.Log(y_true / y_pred), -1);
        }
public override Tensor Forward ( Tensor preds , Tensor labels ) { var y_true = K . Clip ( labels , K . Epsilon ( ) , 1 ) ; var y_pred = K . Clip ( preds , K . Epsilon ( ) , 1 ) ; return K . Sum ( y_true * K . Log ( y_true / y_pred ) , - 1 ) ; }
Forwards the inputs and calculate the loss.
Forwards the inputs and calculate the loss .
None
preds
Tensor
The predicted result.
The predicted result .
labels
Tensor
The true result.
The true result .