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","]",")","}",")",">"]
code: def __init__(
      self,
      pos_inds: Tensor,
      neg_inds: Tensor,
      priors: Tensor,
      gt_bboxes: Tensor,
      assign_result: AssignResult,
      gt_flags: Tensor,
      avg_factor_with_neg: bool = True,
  ) -> None:
      self.pos_inds = pos_inds
      self.neg_inds = neg_inds
      self.num_pos = max(pos_inds.numel(), 1)
      self.num_neg = max(neg_inds.numel(), 1)
      self.avg_factor_with_neg = avg_factor_with_neg
      self.avg_factor = (
          self.num_pos + self.num_neg
          if avg_factor_with_neg
          else self.num_pos
      )
      self.pos_priors = priors[pos_inds]
      self.neg_priors = priors[neg_inds]
      self.pos_is_gt = gt_flags[pos_inds]
  
      self.num_gts = gt_bboxes.shape[0]
      self.pos_assigned_gt_inds = assign_result.gt_inds[pos_inds] - 1
      self.pos_gt_labels = assign_result.labels[pos_inds]
      box_dim = (
          gt_bboxes.box_dim if isinstance(gt_bboxes, BaseBoxes) else 4
      )
      if gt_bboxes.numel() == 0:
          # hack for index error case
          assert self.pos_assigned_gt_inds.numel() == 0
          self.pos_gt_bboxes = gt_bboxes.view(-1, box_dim)
      else:
          if len(gt_bboxes.shape) < 2:
              gt_bboxes = gt_bboxes.view(-1, box_dim)
          self.pos_gt_bboxes = gt_bboxes[
              self.pos_assigned_gt_inds.long()
          ]
  
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 1 to create a new SamplingResult object from inherited base classes: util_mixins with example: obj = SamplingResult(pos_inds, neg_inds, priors, gt_bboxes, assign_result, gt_flags, avg_factor_with_neg)