class_docstr: This class computes an assignment between the targets and the
  predictions of the network For efficiency reasons, the targets don't
  include the no_object.
  
  Because of this, in general, there are more predictions than targets. In
  this case, we do a 1-to-k (dynamic) matching of the best predictions, while
  the others are un-matched (and thus treated as non-objects).
docstr: Use IoU and matching cost to calculate the dynamic top-k positive
  targets.
docstr_tok: ["Use","IoU","and","matching","cost","to","calculate","the","dynamic","top-k","positive","targets","."]
code: def dynamic_k_matching(
      self, cost: Tensor, pairwise_ious: Tensor, num_gt: int
  ) -> Tuple[Tensor, Tensor]:
      """Use IoU and matching cost to calculate the dynamic top-k positive
      targets."""
      matching_matrix = torch.zeros_like(cost)
      # select candidate topk ious for dynamic-k calculation
      candidate_topk = min(self.candidate_topk, pairwise_ious.size(0))
      topk_ious, _ = torch.topk(pairwise_ious, candidate_topk, dim=0)
      # calculate dynamic k for each gt
      dynamic_ks = torch.clamp(topk_ious.sum(0).int(), min=1)
      for gt_idx in range(num_gt):
          _, pos_idx = torch.topk(
              cost[:, gt_idx], k=dynamic_ks[gt_idx], largest=False
          )
          matching_matrix[:, gt_idx][pos_idx] = 1
  
      del topk_ious, dynamic_ks, pos_idx
  
      prior_match_gt_mask = matching_matrix.sum(1) > 1
      if prior_match_gt_mask.sum() > 0:
          _, cost_argmin = torch.min(
              cost[prior_match_gt_mask, :], dim=1
          )
          matching_matrix[prior_match_gt_mask, :] *= 0
          matching_matrix[prior_match_gt_mask, cost_argmin] = 1
  
      while (matching_matrix.sum(0) == 0).any():
          matched_query_id = matching_matrix.sum(1) > 0
          cost[matched_query_id] += 100000.0
          unmatch_id = torch.nonzero(
              matching_matrix.sum(0) == 0, as_tuple=False
          ).squeeze(1)
          for gt_idx in unmatch_id:
              pos_idx = torch.argmin(cost[:, gt_idx])
              matching_matrix[:, gt_idx][pos_idx] = 1.0
          if (matching_matrix.sum(1) > 1).sum() > 0:
              _, cost_argmin = torch.min(
                  cost[prior_match_gt_mask], dim=1
              )
              matching_matrix[prior_match_gt_mask] *= 0
              matching_matrix[
                  prior_match_gt_mask,
                  cost_argmin,
              ] = 1
  
      assert not (matching_matrix.sum(0) == 0).any()
      # get foreground mask inside box and center prior
      fg_mask_inboxes = matching_matrix.sum(1) > 0
      matched_gt_inds = matching_matrix[fg_mask_inboxes, :].argmax(1)
  
      return fg_mask_inboxes, matched_gt_inds
  
imports: from typing import List, Tuple, Union
  import torch
  import torch.nn
  from mmengine.config import ConfigDict
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures.bbox import bbox_cxcywh_to_xyxy, bbox_xyxy_to_cxcywh
  from mmdet.utils import ConfigType
label_desc: Use image node_id 5 for calling the DiffusionDetMatcher obj's underlying member method code with example usage: obj.dynamic_k_matching(cost, pairwise_ious, num_gt) and returns: fg_mask_inboxes,  matched_gt_inds