SiaNet/Losses/BinaryCrossentropy.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)
        {
            Tensor output = preds;
            if (!FromLogit)
            {
                output = K.Clip(output, K.Epsilon(), 1f - K.Epsilon());
                output = K.Log(output / (1 - output));
            }
            output = K.Sigmoid(output);
            return labels * K.Neg(K.Log(output)) + (1 - labels) * K.Neg(K.Log(1 - output));
        }
public override Tensor Forward ( Tensor preds , Tensor labels ) { Tensor output = preds ; if ( ! FromLogit ) { output = K . Clip ( output , K . Epsilon ( ) , 1f - K . Epsilon ( ) ) ; output = K . Log ( output / ( 1 - output ) ) ; } output = K . Sigmoid ( output ) ; return labels * K . Neg ( K . Log ( output ) ) + ( 1 - labels ) * K . Neg ( K . Log ( 1 - output ) ) ; }
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 .