class_docstr: Online Hard Example Mining Sampler described in `Training Region-based
  Object Detectors with Online Hard Example Mining
  <https://arxiv.org/abs/1604.03540>`_.
docstr: Sample negative boxes.
  
  Args:
      assign_result (:obj:`AssignResult`): Assigned results
      num_expected (int): Number of expected negative samples
      bboxes (torch.Tensor, optional): Boxes. Defaults to None.
      feats (list[torch.Tensor], optional): Multi-level features.
          Defaults to None.
  
  Returns:
      torch.Tensor: Indices  of negative samples
docstr_tok: ["Sample","negative","boxes",".","Args",":","assign_result","(",":","obj",":","`","AssignResult","`",")",":","Assigned","results","num_expected","(","int",")",":","Number","of","expected","negative","samples","bboxes","(","torch.Tensor",",","optional",")",":","Boxes",".","Defaults","to","None",".","feats","(","list","[","torch.Tensor","]",",","optional",")",":","Multi-level","features",".","Defaults","to","None",".","Returns",":","torch.Tensor",":","Indices","of","negative","samples"]
code: def _sample_neg(
      self,
      assign_result,
      num_expected,
      bboxes=None,
      feats=None,
      **kwargs,
  ):
      """Sample negative boxes.
  
      Args:
          assign_result (:obj:`AssignResult`): Assigned results
          num_expected (int): Number of expected negative samples
          bboxes (torch.Tensor, optional): Boxes. Defaults to None.
          feats (list[torch.Tensor], optional): Multi-level features.
              Defaults to None.
  
      Returns:
          torch.Tensor: Indices  of negative samples
      """
      # Sample some hard negative samples
      neg_inds = torch.nonzero(
          assign_result.gt_inds == 0, as_tuple=False
      )
      if neg_inds.numel() != 0:
          neg_inds = neg_inds.squeeze(1)
      if len(neg_inds) <= num_expected:
          return neg_inds
      else:
          neg_labels = assign_result.labels.new_empty(
              neg_inds.size(0)
          ).fill_(self.bbox_head.num_classes)
          return self.hard_mining(
              neg_inds,
              num_expected,
              bboxes[neg_inds],
              neg_labels,
              feats,
          )
  
file_path: mmdetection/mmdet/models/task_modules/samplers/ohem_sampler.py
imports: import torch
  from mmdet.registry import TASK_UTILS
  from mmdet.structures.bbox import bbox2roi
  from .base_sampler import BaseSampler
label_desc: Use image node_id 4 for calling the OHEMSampler obj's underlying member method code with example usage: obj._sample_neg(assign_result, num_expected, bboxes, feats) and returns: neg_inds, self