torch.nn.modules.loss — PyTorch 1.10.1 documentation
pytorch.org › _modules › torchThe loss function for each sample in the mini-batch is:.. math:: L(a, p, n) = \max \{d(a_i, p_i) - d(a_i, n_i) + {\rm margin}, 0\} where.. math:: d(x_i, y_i) = \left\lVert {\bf x}_i - {\bf y}_i \right\rVert_p See also :class:`~torch.nn.TripletMarginWithDistanceLoss`, which computes the triplet margin loss for input tensors using a custom distance function.