code: def test_balanced_positive_negative_sampler(self):
      sampler = _utils.BalancedPositiveNegativeSampler(4, 0.25)
      # keep all 6 negatives first, then add 3 positives, last two are ignore
      matched_idxs = [torch.tensor([0, 0, 0, 0, 0, 0, 1, 1, 1, -1, -1])]
      pos, neg = sampler(matched_idxs)
      # we know the number of elements that should be sampled for the positive (1)
      # and the negative (3), and their location. Let's make sure that they are
      # there
      assert pos[0].sum() == 1
      assert pos[0][6:9].sum() == 1
      assert neg[0].sum() == 3
      assert neg[0][0:6].sum() == 3
  
file_path: vision/test/test_models_detection_utils.py
imports: import copy
  import pytest
  import torch
  from common_utils import assert_equal
  from torchvision.models.detection import _utils, backbone_utils
  from torchvision.models.detection.transform import GeneralizedRCNNTransform
label_desc: Use image node_id 1 for calling the TestModelsDetectionUtils obj's underlying member method code with example usage: obj.test_balanced_positive_negative_sampler() without return types