class_docstr: The roi embed head.
  
  This module is used in multi-object tracking methods, such as MaskTrack
  R-CNN.
  
  Args:
      num_convs (int): The number of convoluational layers to embed roi
          features. Defaults to 0.
      num_fcs (int): The number of fully connection layers to embed roi
          features. Defaults to 0.
      roi_feat_size (int|tuple(int)): The spatial size of roi features.
          Defaults to 7.
      in_channels (int): The input channel of roi features. Defaults to 256.
      conv_out_channels (int): The output channel of roi features after
          forwarding convoluational layers. Defaults to 256.
      with_avg_pool (bool): Whether use average pooling before passing roi
          features into fully connection layers. Defaults to False.
      fc_out_channels (int): The output channel of roi features after
          forwarding fully connection layers. Defaults to 1024.
      conv_cfg (dict): Config dict for convolution layer. Defaults to None,
          which means using conv2d.
      norm_cfg (dict): Config dict for normalization layer. Defaults to None.
      loss_match (dict): The loss function. Defaults to
          dict(type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)
      init_cfg (dict): Configuration of initialization. Defaults to None.
class_docstr_tok: ["The","roi","embed","head",".","This","module","is","used","in","multi-object","tracking","methods",",","such","as","MaskTrack","R-CNN",".","Args",":","num_convs","(","int",")",":","The","number","of","convoluational","layers","to","embed","roi","features",".","Defaults","to","0.","num_fcs","(","int",")",":","The","number","of","fully","connection","layers","to","embed","roi","features",".","Defaults","to","0.","roi_feat_size","(","int|tuple","(","int",")",")",":","The","spatial","size","of","roi","features",".","Defaults","to","7.","in_channels","(","int",")",":","The","input","channel","of","roi","features",".","Defaults","to","256.","conv_out_channels","(","int",")",":","The","output","channel","of","roi","features","after","forwarding","convoluational","layers",".","Defaults","to","256.","with_avg_pool","(","bool",")",":","Whether","use","average","pooling","before","passing","roi","features","into","fully","connection","layers",".","Defaults","to","False",".","fc_out_channels","(","int",")",":","The","output","channel","of","roi","features","after","forwarding","fully","connection","layers",".","Defaults","to","1024.","conv_cfg","(","dict",")",":","Config","dict","for","convolution","layer",".","Defaults","to","None",",","which","means","using","conv2d",".","norm_cfg","(","dict",")",":","Config","dict","for","normalization","layer",".","Defaults","to","None",".","loss_match","(","dict",")",":","The","loss","function",".","Defaults","to","dict","(","type='CrossEntropyLoss","'",",","use_sigmoid=False",",","loss_weight=1.0",")","init_cfg","(","dict",")",":","Configuration","of","initialization",".","Defaults","to","None","."]
docstr: Calculate the loss in a batch.
  
  Args:
      bbox_feats (Tensor): of shape [N, C, H, W]. N is the number of
          bboxes.
      ref_bbox_feats (Tensor): of shape [M, C, H, W]. M is the number of
          reference bboxes.
      num_bbox_per_img (list[int]): The `bbox_feats` contains proposals
          of multi-images. `num_bbox_per_img` denotes the number of
          proposals for each key image.
      num_bbox_per_ref_img (list[int]): The `ref_bbox_feats` contains
          proposals of multi-images. `num_bbox_per_ref_img` denotes the
          number of proposals for each reference image.
      sampling_results (List[obj:SamplingResult]): Assign results of
          all images in a batch after sampling.
      gt_instance_ids (list[Tensor]): The instance ids of gt_bboxes of
          all images in a batch, each tensor has shape (num_gt, ).
      ref_gt_instance_ids (list[Tensor]): The instance ids of gt_bboxes
          of all reference images in a batch, each tensor has shape
          (num_gt, ).
      reduction_override (str, optional): The method used to reduce the
          loss. Options are "none", "mean" and "sum".
  
  Returns:
      dict[str, Tensor]: a dictionary of loss components.
docstr_tok: ["Calculate","the","loss","in","a","batch",".","Args",":","bbox_feats","(","Tensor",")",":","of","shape","[","N",",","C",",","H",",","W","]",".","N","is","the","number","of","bboxes",".","ref_bbox_feats","(","Tensor",")",":","of","shape","[","M",",","C",",","H",",","W","]",".","M","is","the","number","of","reference","bboxes",".","num_bbox_per_img","(","list","[","int","]",")",":","The","`","bbox_feats","`","contains","proposals","of","multi-images",".","`","num_bbox_per_img","`","denotes","the","number","of","proposals","for","each","key","image",".","num_bbox_per_ref_img","(","list","[","int","]",")",":","The","`","ref_bbox_feats","`","contains","proposals","of","multi-images",".","`","num_bbox_per_ref_img","`","denotes","the","number","of","proposals","for","each","reference","image",".","sampling_results","(","List","[","obj",":","SamplingResult","]",")",":","Assign","results","of","all","images","in","a","batch","after","sampling",".","gt_instance_ids","(","list","[","Tensor","]",")",":","The","instance","ids","of","gt_bboxes","of","all","images","in","a","batch",",","each","tensor","has","shape","(","num_gt",",",")",".","ref_gt_instance_ids","(","list","[","Tensor","]",")",":","The","instance","ids","of","gt_bboxes","of","all","reference","images","in","a","batch",",","each","tensor","has","shape","(","num_gt",",",")",".","reduction_override","(","str",",","optional",")",":","The","method","used","to","reduce","the","loss",".","Options","are","``","none","''",",","``","mean","''","and","``","sum","''",".","Returns",":","dict","[","str",",","Tensor","]",":","a","dictionary","of","loss","components","."]
code: def loss(
      self,
      bbox_feats: Tensor,
      ref_bbox_feats: Tensor,
      num_bbox_per_img: int,
      num_bbox_per_ref_img: int,
      sampling_results: List[SamplingResult],
      gt_instance_ids: List[Tensor],
      ref_gt_instance_ids: List[Tensor],
      reduction_override: Optional[str] = None,
  ) -> dict:
      """Calculate the loss in a batch.
  
      Args:
          bbox_feats (Tensor): of shape [N, C, H, W]. N is the number of
              bboxes.
          ref_bbox_feats (Tensor): of shape [M, C, H, W]. M is the number of
              reference bboxes.
          num_bbox_per_img (list[int]): The `bbox_feats` contains proposals
              of multi-images. `num_bbox_per_img` denotes the number of
              proposals for each key image.
          num_bbox_per_ref_img (list[int]): The `ref_bbox_feats` contains
              proposals of multi-images. `num_bbox_per_ref_img` denotes the
              number of proposals for each reference image.
          sampling_results (List[obj:SamplingResult]): Assign results of
              all images in a batch after sampling.
          gt_instance_ids (list[Tensor]): The instance ids of gt_bboxes of
              all images in a batch, each tensor has shape (num_gt, ).
          ref_gt_instance_ids (list[Tensor]): The instance ids of gt_bboxes
              of all reference images in a batch, each tensor has shape
              (num_gt, ).
          reduction_override (str, optional): The method used to reduce the
              loss. Options are "none", "mean" and "sum".
  
      Returns:
          dict[str, Tensor]: a dictionary of loss components.
      """
      x_split, ref_x_split = self(
          bbox_feats,
          ref_bbox_feats,
          num_bbox_per_img,
          num_bbox_per_ref_img,
      )
  
      losses = self.loss_by_feat(
          x_split,
          ref_x_split,
          sampling_results,
          gt_instance_ids,
          ref_gt_instance_ids,
          reduction_override,
      )
      return losses
  
imports: from collections import defaultdict
  from typing import List, Optional, Tuple
  import torch
  import torch.nn
  from mmcv.cnn import ConvModule
  from mmengine.model import BaseModule
  from torch import Tensor
  from torch.nn.modules.utils import _pair
  from mmdet.models.losses import accuracy
  from mmdet.models.task_modules import SamplingResult
  from mmdet.models.task_modules.tracking import embed_similarity
  from mmdet.registry import MODELS
label_desc: Use image node_id 7 for calling the RoIEmbedHead obj's underlying member method code with example usage: obj.loss(bbox_feats, ref_bbox_feats, num_bbox_per_img, num_bbox_per_ref_img, sampling_results, gt_instance_ids, ref_gt_instance_ids, reduction_override) and returns: losses