SiaNet/Losses/CosineProximity.cs
/// <summary>
/// Backpropagation method to calculate gradient of the loss function
/// </summary>
/// <param name="preds">The predicted result.</param>
/// <param name="labels">The true result.</param>
/// <returns></returns>
Backpropagation method to calculate gradient of the loss function
Backpropagation method to calculate gradient of the loss function
public override Tensor Backward(Tensor preds, Tensor labels)
        {
            var y_true = K.Max(K.Sum(labels, -1), -1) / (K.Abs(preds * K.Abs(labels)));
            var y_pred = K.Max(K.Sum(preds, -1), -1) / K.Square(K.Abs(preds));
            return y_true + _cossine_sim(preds, labels) * y_pred;
        }
public override Tensor Backward ( Tensor preds , Tensor labels ) { var y_true = K . Max ( K . Sum ( labels , - 1 ) , - 1 ) / ( K . Abs ( preds * K . Abs ( labels ) ) ) ; var y_pred = K . Max ( K . Sum ( preds , - 1 ) , - 1 ) / K . Square ( K . Abs ( preds ) ) ; return y_true + _cossine_sim ( preds , labels ) * y_pred ; }
Backpropagation method to calculate gradient of the loss function
Backpropagation method to calculate gradient of the loss function
None
preds
Tensor
The predicted result.
The predicted result .
labels
Tensor
The true result.
The true result .