W3cubDocs

/PyTorch 2.9

torch.nn.functional.triplet_margin_loss

torch.nn.functional.triplet_margin_loss(anchor, positive, negative, margin=1.0, p=2, eps=1e-06, swap=False, size_average=None, reduce=None, reduction='mean') [source]

Compute the triplet loss between given input tensors and a margin greater than 0.

See TripletMarginLoss for details.

Return type

Tensor

© 2025, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://docs.pytorch.org/docs/2.9/generated/torch.nn.functional.triplet_margin_loss.html