class_docstr: Random sampler for multi instance.
  
  Note:
      Multi-instance means to predict multiple detection boxes with
      one proposal box. `AssignResult` may assign multiple gt boxes
      to each proposal box, in this case `RandomSampler` should be
      replaced by `MultiInsRandomSampler`
class_docstr_tok: ["Random","sampler","for","multi","instance",".","Note",":","Multi-instance","means","to","predict","multiple","detection","boxes","with","one","proposal","box",".","`","AssignResult","`","may","assign","multiple","gt","boxes","to","each","proposal","box",",","in","this","case","`","RandomSampler","`","should","be","replaced","by","`","MultiInsRandomSampler","`"]
docstr: Randomly sample some positive 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","positive","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_pos(
      self, assign_result: AssignResult, num_expected: int, **kwargs
  ) -> Union[Tensor, ndarray]:
      """Randomly sample some positive samples.
  
      Args:
          assign_result (:obj:`AssignResult`): Bbox assigning results.
          num_expected (int): The number of expected positive samples
  
      Returns:
          Tensor or ndarray: sampled indices.
      """
      pos_inds = torch.nonzero(
          assign_result.labels[:, 0] > 0, as_tuple=False
      )
      if pos_inds.numel() != 0:
          pos_inds = pos_inds.squeeze(1)
      if pos_inds.numel() <= num_expected:
          return pos_inds
      else:
          return self.random_choice(pos_inds, num_expected)
  
file_path: mmdetection/mmdet/models/task_modules/samplers/multi_instance_random_sampler.py
imports: from typing import Union
  import torch
  from mmengine.structures import InstanceData
  from numpy import ndarray
  from torch import Tensor
  from mmdet.registry import TASK_UTILS
  from ..assigners import AssignResult
  from .multi_instance_sampling_result import MultiInstanceSamplingResult
  from .random_sampler import RandomSampler
label_desc: Use image node_id 1 for calling the MultiInsRandomSampler obj's underlying member method code with example usage: obj._sample_pos(assign_result, num_expected) and returns: pos_inds, self