class_docstr: This class samples batches, ensuring that they contain a fixed proportion of positives
class_docstr_tok: ["This","class","samples","batches",",","ensuring","that","they","contain","a","fixed","proportion","of","positives"]
docstr: Args:
      batch_size_per_image (int): number of elements to be selected per image
      positive_fraction (float): percentage of positive elements per batch
docstr_tok: ["Args",":","batch_size_per_image","(","int",")",":","number","of","elements","to","be","selected","per","image","positive_fraction","(","float",")",":","percentage","of","positive","elements","per","batch"]
code: def __init__(
      self, batch_size_per_image: int, positive_fraction: float
  ) -> None:
      """
      Args:
          batch_size_per_image (int): number of elements to be selected per image
          positive_fraction (float): percentage of positive elements per batch
      """
      self.batch_size_per_image = batch_size_per_image
      self.positive_fraction = positive_fraction
  
imports: import math
  from collections import OrderedDict
  from typing import Dict, List, Optional, Tuple
  import torch
  from torch import nn, Tensor
  from torch.nn import functional
  from torchvision.ops import complete_box_iou_loss, distance_box_iou_loss, FrozenBatchNorm2d, generalized_box_iou_loss
label_desc: Use image node_id 1 to create a new BalancedPositiveNegativeSampler object  with example: obj = BalancedPositiveNegativeSampler(batch_size_per_image, positive_fraction)