code: def compute_loss(self, weights):
      dtype, device = weights.dtype, weights.device
      num_classes = weights.size(0)
      cos = self.distance(weights)
      with torch.no_grad():
          cos1 = cos.clone()
          cos1.fill_diagonal_(c_f.neg_inf(dtype))
          _, indices = self.distance.smallest_dist(cos1, dim=1)
          mask = torch.zeros(
              (num_classes, num_classes), dtype=dtype, device=device
          )
          row_nums = torch.arange(
              num_classes, device=device, dtype=torch.long
          )
          mask[row_nums, indices] = 1
      losses = torch.sum(cos * mask, dim=1)
      return {
          "loss": {
              "losses": losses,
              "indices": c_f.torch_arange_from_size(weights),
              "reduction_type": "element",
          }
      }
  
file_path: pytorch-metric-learning/src/pytorch_metric_learning/regularizers/regular_face_regularizer.py
imports: import torch
  from ..distances import CosineSimilarity
  from ..utils import common_functions
  from .base_regularizer import BaseRegularizer
label_desc: Use image node_id 2 for calling the RegularFaceRegularizer obj's underlying member method code with example usage: obj.compute_loss(weights) and returns: dict