docstr: Test roi embed head loss when truth is non-empty.
docstr_tok: ["Test","roi","embed","head","loss","when","truth","is","non-empty","."]
code: def test_roi_embed_head_loss(self):
      """Test roi embed head loss when truth is non-empty."""
      cfg = mmengine.Config(
          dict(
              num_convs=2,
              num_fcs=2,
              roi_feat_size=7,
              in_channels=16,
              fc_out_channels=32,
          )
      )
  
      embed_head = RoIEmbedHead(**cfg)
  
      x = torch.rand(1, 16, 7, 7)
      ref_x = torch.rand(1, 16, 7, 7)
      num_x_per_img = [1]
      num_x_per_ref_img = [1]
      x_split, ref_x_split = embed_head.forward(
          x, ref_x, num_x_per_img, num_x_per_ref_img
      )
  
      gt_instance_ids = [torch.LongTensor([2])]
      ref_gt_instance_ids = [torch.LongTensor([2])]
  
      rpn_results = InstanceData()
      rpn_results.labels = torch.LongTensor([2])
      rpn_results.priors = torch.Tensor(
          [[23.6667, 23.8757, 238.6326, 151.8874]]
      )
      rpn_results_list = [rpn_results]
  
      gt_instance = InstanceData()
      gt_instance.labels = torch.LongTensor([2])
      gt_instance.bboxes = torch.Tensor(
          [[23.6667, 23.8757, 238.6326, 151.8874]]
      )
      gt_instance.instances_id = torch.LongTensor([2])
      batch_gt_instances = [gt_instance]
  
      sampling_results = _dummy_bbox_sampling(
          rpn_results_list, batch_gt_instances
      )
  
      gt_losses = embed_head.loss_by_feat(
          x_split,
          ref_x_split,
          sampling_results,
          gt_instance_ids,
          ref_gt_instance_ids,
      )
      assert (
          gt_losses["loss_match"] > 0
      ), "match loss should be non-zero"
      assert (
          gt_losses["match_accuracy"] >= 0
      ), "match accuracy should be non-zero or zero"
  
file_path: mmdetection/tests/test_models/test_tracking_heads/test_roi_embed_head.py
imports: from unittest import TestCase
  import mmengine
  import torch
  from mmengine.structures import InstanceData
  from mmdet.models.tracking_heads import RoIEmbedHead
  from mmdet.registry import TASK_UTILS
label_desc: Use image node_id 1 for calling the TestRoIEmbedHead obj's underlying member method code with example usage: obj.test_roi_embed_head_loss() without return types