code: def compute_rpn_class_loss(
      rpn_match, rpn_class_logits, shem_poolsize
  ):
      """
      :param rpn_match: (n_anchors). [-1, 0, 1] for negative, neutral, and positive matched anchors.
      :param rpn_class_logits: (n_anchors, 2). logits from RPN classifier.
      :param shem_poolsize: int. factor of top-k candidates to draw from per negative sample
      (stochastic-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.
      """
  
      # filter out neutral anchors.
      pos_indices = torch.nonzero(rpn_match == 1)
      neg_indices = torch.nonzero(rpn_match == -1)
  
      # loss for positive samples
      if 0 not in pos_indices.size():
          pos_indices = pos_indices.squeeze(1)
          roi_logits_pos = rpn_class_logits[pos_indices]
          pos_loss = F.cross_entropy(
              roi_logits_pos,
              torch.LongTensor([1] * pos_indices.shape[0]).cuda(),
          )
      else:
          pos_loss = torch.FloatTensor([0]).cuda()
  
      # loss for negative samples: draw hard negative examples (SHEM)
      # that match the number of positive samples, but at least 1.
      if 0 not in neg_indices.size():
          neg_indices = neg_indices.squeeze(1)
          roi_logits_neg = rpn_class_logits[neg_indices]
          negative_count = np.max(
              (1, pos_indices.cpu().data.numpy().size)
          )
          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(),
          )
          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
  from cuda_functions.nms_2D.pth_nms import nms_gpu
  from cuda_functions.nms_3D.pth_nms import nms_gpu
  from cuda_functions.roi_align_2D.roi_align.crop_and_resize import CropAndResizeFunction
  from cuda_functions.roi_align_3D.roi_align.crop_and_resize import CropAndResizeFunction
  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_rpn_class_loss(rpn_match, rpn_class_logits, shem_poolsize) and returns: loss,  np_neg_ix