class_docstr: Random sampler.
  
  Args:
      num (int): Number of samples
      pos_fraction (float): Fraction of positive samples
      neg_pos_up (int): Upper bound number of negative and
          positive samples. Defaults to -1.
      add_gt_as_proposals (bool): Whether to add ground truth
          boxes as proposals. Defaults to True.
class_docstr_tok: ["Random","sampler",".","Args",":","num","(","int",")",":","Number","of","samples","pos_fraction","(","float",")",":","Fraction","of","positive","samples","neg_pos_up","(","int",")",":","Upper","bound","number","of","negative","and","positive","samples",".","Defaults","to","-1.","add_gt_as_proposals","(","bool",")",":","Whether","to","add","ground","truth","boxes","as","proposals",".","Defaults","to","True","."]
docstr: Randomly sample some negative samples.
  
  Args:
      assign_result (:obj:`AssignResult`): Bbox assigning results.
      num_expected (int): The number of expected positive samples
  
  Returns:
      Tensor or ndarray: sampled indices.
docstr_tok: ["Randomly","sample","some","negative","samples",".","Args",":","assign_result","(",":","obj",":","`","AssignResult","`",")",":","Bbox","assigning","results",".","num_expected","(","int",")",":","The","number","of","expected","positive","samples","Returns",":","Tensor","or","ndarray",":","sampled","indices","."]
code: def _sample_neg(
      self, assign_result: AssignResult, num_expected: int, **kwargs
  ) -> Union[Tensor, ndarray]:
      """Randomly sample some negative samples.
  
      Args:
          assign_result (:obj:`AssignResult`): Bbox assigning results.
          num_expected (int): The number of expected positive samples
  
      Returns:
          Tensor or ndarray: sampled indices.
      """
      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:
          return self.random_choice(neg_inds, num_expected)
  
file_path: mmdetection/mmdet/models/task_modules/samplers/random_sampler.py
imports: from typing import Union
  import torch
  from numpy import ndarray
  from torch import Tensor
  from mmdet.registry import TASK_UTILS
  from ..assigners import AssignResult
  from .base_sampler import BaseSampler
label_desc: Use image node_id 4 for calling the RandomSampler obj's underlying member method code with example usage: obj._sample_neg(assign_result, num_expected) and returns: neg_inds, self