code: def test_targets_to_anchors(self):
      _, targets = self._make_empty_sample()
      anchors = [torch.randint(-50, 50, (3, 4), dtype=torch.float32)]
  
      anchor_sizes = ((32,), (64,), (128,), (256,), (512,))
      aspect_ratios = ((0.5, 1.0, 2.0),) * len(anchor_sizes)
      rpn_anchor_generator = AnchorGenerator(
          anchor_sizes, aspect_ratios
      )
      rpn_head = RPNHead(
          4, rpn_anchor_generator.num_anchors_per_location()[0]
      )
  
      head = RegionProposalNetwork(
          rpn_anchor_generator,
          rpn_head,
          0.5,
          0.3,
          256,
          0.5,
          2000,
          2000,
          0.7,
          0.05,
      )
  
      labels, matched_gt_boxes = head.assign_targets_to_anchors(
          anchors, targets
      )
  
      assert labels[0].sum() == 0
      assert labels[0].shape == torch.Size([anchors[0].shape[0]])
      assert labels[0].dtype == torch.float32
  
      assert matched_gt_boxes[0].sum() == 0
      assert matched_gt_boxes[0].shape == anchors[0].shape
      assert matched_gt_boxes[0].dtype == torch.float32
  
file_path: vision/test/test_models_detection_negative_samples.py
imports: import pytest
  import torch
  import torchvision.models
  from common_utils import assert_equal
  from torchvision.models.detection.faster_rcnn import FastRCNNPredictor, TwoMLPHead
  from torchvision.models.detection.roi_heads import RoIHeads
  from torchvision.models.detection.rpn import AnchorGenerator, RegionProposalNetwork, RPNHead
  from torchvision.ops import MultiScaleRoIAlign
label_desc: Use image node_id 2 for calling the TestModelsDetectionNegativeSamples obj's underlying member method code with example usage: obj.test_targets_to_anchors() without return types