Tensorflow.js tf.losses.absoluteDifference() Function
The Tensorflow.js tf.losses.absoluteDifference() function calculates the absolute difference loss between two given tensors.
tf.losses.absoluteDifference(labels, predictions, weights, reduction);
- labels: It specifies the truth output tensor. The absolute difference is predicted based on this tensor.
- predictions: It specifies the predicted output tensor with the same dimensions as labels.
- weights: It specifies a tensor of rank either equal to that of labels so that it can be broadcastable or 0. It is an optional parameter.
- reduction: It specifies the type of reduction to the loss. It is optional.
Return Value: It returns a tf.Tensor which is calculated by absoluteDifference() function.
Example 1: In this example we will take two 2d tensors as labels and prediction. Then we will find the absolute difference loss of these two.
Example 2: Taking weights of rank as of labels in the absolute function and then calculate the absolute difference.