code: def compute_class_loss(
      anchor_matches, class_pred_logits, shem_poolsize=20
  ):
      """
      :param anchor_matches: (n_anchors). [-1, 0, class_id] for negative, neutral, and positive matched anchors.
      :param class_pred_logits: (n_anchors, n_classes). logits from classifier sub-network.
      :param shem_poolsize: int. factor of top-k candidates to draw from per negative sample (online-hard-example-mining).
      :return: loss: torch tensor.
      :return: np_neg_ix: 1D array containing indices of the neg_roi_logits, which have been sampled for training.
      """
      # Positive and Negative anchors contribute to the loss,
      # but neutral anchors (match value = 0) don't.
      pos_indices = torch.nonzero(anchor_matches > 0)
      neg_indices = torch.nonzero(anchor_matches == -1)
  
      # get positive samples and calucalte loss.
      if 0 not in pos_indices.size():
          pos_indices = pos_indices.squeeze(1)
          roi_logits_pos = class_pred_logits[pos_indices]
          targets_pos = anchor_matches[pos_indices]
          pos_loss = F.cross_entropy(roi_logits_pos, targets_pos.long())
      else:
          pos_loss = torch.FloatTensor([0]).cuda()
  
      # get negative samples, such that the amount matches the number of positive samples, but at least 1.
      # get high scoring negatives by applying online-hard-example-mining.
      if 0 not in neg_indices.size():
          neg_indices = neg_indices.squeeze(1)
          roi_logits_neg = class_pred_logits[neg_indices]
          negative_count = np.max((1, pos_indices.size()[0]))
          roi_probs_neg = F.softmax(roi_logits_neg, dim=1)
          neg_ix = mutils.shem(
              roi_probs_neg, negative_count, shem_poolsize
          )
          neg_loss = F.cross_entropy(
              roi_logits_neg[neg_ix],
              torch.LongTensor([0] * neg_ix.shape[0]).cuda(),
          )
          # return the indices of negative samples, which contributed to the loss (for monitoring plots).
          np_neg_ix = neg_ix.cpu().data.numpy()
      else:
          neg_loss = torch.FloatTensor([0]).cuda()
          np_neg_ix = np.array([]).astype("int32")
  
      loss = (pos_loss + neg_loss) / 2
      return loss, np_neg_ix
  
imports: import utils.model_utils
  import utils.exp_utils
  import sys
  from cuda_functions.nms_2D.pth_nms import nms_gpu
  from cuda_functions.nms_3D.pth_nms import nms_gpu
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils
label_desc: Use image node_id 1 for calling a global function with example usage: compute_class_loss(anchor_matches, class_pred_logits, shem_poolsize) and returns: loss,  np_neg_ix