class_docstr: Bbox sampling result.
  
  Args:
      pos_inds (Tensor): Indices of positive samples.
      neg_inds (Tensor): Indices of negative samples.
      priors (Tensor): The priors can be anchors or points,
          or the bboxes predicted by the previous stage.
      gt_bboxes (Tensor): Ground truth of bboxes.
      assign_result (:obj:`AssignResult`): Assigning results.
      gt_flags (Tensor): The Ground truth flags.
      avg_factor_with_neg (bool):  If True, ``avg_factor`` equal to
          the number of total priors; Otherwise, it is the number of
          positive priors. Defaults to True.
  
  Example:
      >>> # xdoctest: +IGNORE_WANT
      >>> from mmdet.models.task_modules.samplers.sampling_result import *  # NOQA
      >>> self = SamplingResult.random(rng=10)
      >>> print(f'self = {self}')
      self = <SamplingResult({
          'neg_inds': tensor([1,  2,  3,  5,  6,  7,  8,
                              9, 10, 11, 12, 13]),
          'neg_priors': torch.Size([12, 4]),
          'num_gts': 1,
          'num_neg': 12,
          'num_pos': 1,
          'avg_factor': 13,
          'pos_assigned_gt_inds': tensor([0]),
          'pos_inds': tensor([0]),
          'pos_is_gt': tensor([1], dtype=torch.uint8),
          'pos_priors': torch.Size([1, 4])
      })>
class_docstr_tok: ["Bbox","sampling","result",".","Args",":","pos_inds","(","Tensor",")",":","Indices","of","positive","samples",".","neg_inds","(","Tensor",")",":","Indices","of","negative","samples",".","priors","(","Tensor",")",":","The","priors","can","be","anchors","or","points",",","or","the","bboxes","predicted","by","the","previous","stage",".","gt_bboxes","(","Tensor",")",":","Ground","truth","of","bboxes",".","assign_result","(",":","obj",":","`","AssignResult","`",")",":","Assigning","results",".","gt_flags","(","Tensor",")",":","The","Ground","truth","flags",".","avg_factor_with_neg","(","bool",")",":","If","True",",","``","avg_factor","``","equal","to","the","number","of","total","priors",";","Otherwise",",","it","is","the","number","of","positive","priors",".","Defaults","to","True",".","Example",":",">",">",">","#","xdoctest",":","+IGNORE_WANT",">",">",">","from","mmdet.models.task_modules.samplers.sampling_result","import","*","#","NOQA",">",">",">","self","=","SamplingResult.random","(","rng=10",")",">",">",">","print","(","f'self","=","{","self","}","'",")","self","=","<","SamplingResult","(","{","'neg_inds","'",":","tensor","(","[","1",",","2",",","3",",","5",",","6",",","7",",","8",",","9",",","10",",","11",",","12",",","13","]",")",",","'neg_priors","'",":","torch.Size","(","[","12",",","4","]",")",",","'num_gts","'",":","1",",","'num_neg","'",":","12",",","'num_pos","'",":","1",",","'avg_factor","'",":","13",",","'pos_assigned_gt_inds","'",":","tensor","(","[","0","]",")",",","'pos_inds","'",":","tensor","(","[","0","]",")",",","'pos_is_gt","'",":","tensor","(","[","1","]",",","dtype=torch.uint8",")",",","'pos_priors","'",":","torch.Size","(","[","1",",","4","]",")","}",")",">"]
docstr: Args:
      rng (None | int | numpy.random.RandomState): seed or state.
      kwargs (keyword arguments):
          - num_preds: Number of predicted boxes.
          - num_gts: Number of true boxes.
          - p_ignore (float): Probability of a predicted box assigned to
              an ignored truth.
          - p_assigned (float): probability of a predicted box not being
              assigned.
  
  Returns:
      :obj:`SamplingResult`: Randomly generated sampling result.
  
  Example:
      >>> from mmdet.models.task_modules.samplers.sampling_result import *  # NOQA
      >>> self = SamplingResult.random()
      >>> print(self.__dict__)
docstr_tok: ["Args",":","rng","(","None","|","int","|","numpy.random.RandomState",")",":","seed","or","state",".","kwargs","(","keyword","arguments",")",":","-","num_preds",":","Number","of","predicted","boxes",".","-","num_gts",":","Number","of","true","boxes",".","-","p_ignore","(","float",")",":","Probability","of","a","predicted","box","assigned","to","an","ignored","truth",".","-","p_assigned","(","float",")",":","probability","of","a","predicted","box","not","being","assigned",".","Returns",":",":","obj",":","`","SamplingResult","`",":","Randomly","generated","sampling","result",".","Example",":",">",">",">","from","mmdet.models.task_modules.samplers.sampling_result","import","*","#","NOQA",">",">",">","self","=","SamplingResult.random","(",")",">",">",">","print","(","self.__dict__",")"]
code: def random(cls, rng=None, **kwargs):
      """
      Args:
          rng (None | int | numpy.random.RandomState): seed or state.
          kwargs (keyword arguments):
              - num_preds: Number of predicted boxes.
              - num_gts: Number of true boxes.
              - p_ignore (float): Probability of a predicted box assigned to
                  an ignored truth.
              - p_assigned (float): probability of a predicted box not being
                  assigned.
  
      Returns:
          :obj:`SamplingResult`: Randomly generated sampling result.
  
      Example:
          >>> from mmdet.models.task_modules.samplers.sampling_result import *  # NOQA
          >>> self = SamplingResult.random()
          >>> print(self.__dict__)
      """
      from mmengine.structures import InstanceData
  
      from mmdet.models.task_modules.assigners import AssignResult
      from mmdet.models.task_modules.samplers import RandomSampler
  
      rng = ensure_rng(rng)
  
      # make probabilistic?
      num = 32
      pos_fraction = 0.5
      neg_pos_ub = -1
  
      assign_result = AssignResult.random(rng=rng, **kwargs)
  
      # Note we could just compute an assignment
      priors = random_boxes(assign_result.num_preds, rng=rng)
      gt_bboxes = random_boxes(assign_result.num_gts, rng=rng)
      gt_labels = torch.randint(
          0, 5, (assign_result.num_gts,), dtype=torch.long
      )
  
      pred_instances = InstanceData()
      pred_instances.priors = priors
  
      gt_instances = InstanceData()
      gt_instances.bboxes = gt_bboxes
      gt_instances.labels = gt_labels
  
      add_gt_as_proposals = True
  
      sampler = RandomSampler(
          num,
          pos_fraction,
          neg_pos_ub=neg_pos_ub,
          add_gt_as_proposals=add_gt_as_proposals,
          rng=rng,
      )
      self = sampler.sample(
          assign_result=assign_result,
          pred_instances=pred_instances,
          gt_instances=gt_instances,
      )
      return self
  
file_path: mmdetection/mmdet/models/task_modules/samplers/sampling_result.py
imports: import warnings
  import numpy
  import torch
  from torch import Tensor
  from mmdet.structures.bbox import BaseBoxes, cat_boxes
  from mmdet.utils import util_mixins
  from mmdet.utils.util_random import ensure_rng
  from ..assigners import AssignResult
label_desc: Use image node_id 9 for calling the SamplingResult obj's underlying member method code with example usage: obj.random(cls, rng) and returns: self