SiaNet/Losses/CategoricalCrossentropy.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)
        {
            if (FromLogit)
                preds = K.Softmax(preds);
            else
                preds /= K.Sum(preds, -1);
            preds = K.Clip(preds, K.Epsilon(), 1 - K.Epsilon());
            return K.Sum(-1 * labels * K.Log(preds), -1);
        }
public override Tensor Forward ( Tensor preds , Tensor labels ) { if ( FromLogit ) preds = K . Softmax ( preds ) ; else preds /= K . Sum ( preds , - 1 ) ; preds = K . Clip ( preds , K . Epsilon ( ) , 1 - K . Epsilon ( ) ) ; return K . Sum ( - 1 * labels * K . Log ( preds ) , - 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 .