code: def _ohem_loss(
      roi_cls_locs,
      roi_scores,
      gt_roi_locs,
      gt_roi_labels,
      n_ohem_sample,
      roi_sigma=1.0,
  ):
      xp = cuda.get_array_module(roi_cls_locs)
      n_sample = roi_cls_locs.shape[0]
      roi_cls_locs = roi_cls_locs.reshape((n_sample, -1, 4))
      roi_locs = roi_cls_locs[xp.arange(n_sample), gt_roi_labels]
      roi_loc_loss = _fast_rcnn_loc_loss(
          roi_locs, gt_roi_locs, gt_roi_labels, roi_sigma, reduce="no"
      )
      roi_cls_loss = F.softmax_cross_entropy(
          roi_scores, gt_roi_labels, reduce="no"
      )
      assert roi_loc_loss.shape == roi_cls_loss.shape
  
      n_ohem_sample = min(n_ohem_sample, n_sample)
      # sort in CPU because of GPU memory
      roi_cls_loc_loss = cuda.to_cpu(
          roi_loc_loss.array + roi_cls_loss.array
      )
      indices = roi_cls_loc_loss.argsort(axis=0)[::-1]
      # filter nan
      indices = np.array(
          [i for i in indices if not np.isnan(roi_cls_loc_loss[i])],
          dtype=np.int32,
      )
      indices = indices[:n_ohem_sample]
      if cuda.get_array_module(roi_loc_loss.array) != np:
          indices = cuda.to_gpu(indices)
      if len(indices) > 0:
          roi_loc_loss = F.sum(roi_loc_loss[indices]) / n_ohem_sample
          roi_cls_loss = F.sum(roi_cls_loss[indices]) / len(indices)
      else:
          roi_loc_loss = chainer.Variable(
              xp.array(0.0, dtype=xp.float32)
          )
          roi_cls_loss = chainer.Variable(
              xp.array(0.0, dtype=xp.float32)
          )
          roi_loc_loss.zerograd()
          roi_cls_loss.zerograd()
  
      return roi_loc_loss, roi_cls_loss
  
file_path: chainercv/chainercv/links/model/light_head_rcnn/light_head_rcnn_train_chain.py
imports: from __future__ import division
  import numpy
  import warnings
  import chainer
  from chainer.backends import cuda
  import chainer.functions
  from chainercv.links.model.faster_rcnn.utils.anchor_target_creator import AnchorTargetCreator
  from chainercv.links.model.faster_rcnn.utils.proposal_target_creator import ProposalTargetCreator
label_desc: Use image node_id 1 for calling a global function with example usage: _ohem_loss(roi_cls_locs, roi_scores, gt_roi_locs, gt_roi_labels, n_ohem_sample, roi_sigma) and returns: roi_loc_loss,  roi_cls_loss