code: def shem(roi_probs_neg, negative_count, ohem_poolsize):
      """
      stochastic hard example mining: from a list of indices (referring to non-matched predictions),
      determine a pool of highest scoring (worst false positives) of size negative_count*ohem_poolsize.
      Then, sample n (= negative_count) predictions of this pool as negative examples for loss.
      :param roi_probs_neg: tensor of shape (n_predictions, n_classes).
      :param negative_count: int.
      :param ohem_poolsize: int.
      :return: (negative_count).  indices refer to the positions in roi_probs_neg. If pool smaller than expected due to
      limited negative proposals availabel, this function will return sampled indices of number < negative_count without
      throwing an error.
      """
      # sort according to higehst foreground score.
      probs, order = (
          roi_probs_neg[:, 1:].max(1)[0].sort(descending=True)
      )
      select = (
          torch.tensor(
              (ohem_poolsize * int(negative_count), order.size()[0])
          )
          .min()
          .int()
      )
      pool_indices = order[:select]
      rand_idx = torch.randperm(pool_indices.size()[0])
      return pool_indices[rand_idx[:negative_count].cuda()]
  
imports: import numpy
  import scipy.misc
  import scipy.ndimage
  import torch
  from torch.autograd import Variable
  import torch.nn
label_desc: Use image node_id 22 for calling a global function with example usage: shem(roi_probs_neg, negative_count, ohem_poolsize) and returns: pool_indices