docstr: Produce additional matches for predictions that have only low-quality matches.
  Specifically, for each ground-truth find the set of predictions that have
  maximum overlap with it (including ties); for each prediction in that set, if
  it is unmatched, then match it to the ground-truth with which it has the highest
  quality value.
docstr_tok: ["Produce","additional","matches","for","predictions","that","have","only","low-quality","matches",".","Specifically",",","for","each","ground-truth","find","the","set","of","predictions","that","have","maximum","overlap","with","it","(","including","ties",")",";","for","each","prediction","in","that","set",",","if","it","is","unmatched",",","then","match","it","to","the","ground-truth","with","which","it","has","the","highest","quality","value","."]
code: def set_low_quality_matches_(
      self, matches, all_matches, match_quality_matrix
  ):
      """
      Produce additional matches for predictions that have only low-quality matches.
      Specifically, for each ground-truth find the set of predictions that have
      maximum overlap with it (including ties); for each prediction in that set, if
      it is unmatched, then match it to the ground-truth with which it has the highest
      quality value.
      """
      # For each gt, find the prediction with which it has highest quality
      # 对于每个gt boxes寻找与其iou最大的anchor，
      # highest_quality_foreach_gt为匹配到的最大iou值
      highest_quality_foreach_gt, _ = match_quality_matrix.max(
          dim=1
      )  # the dimension to reduce.
  
      # Find highest quality match available, even if it is low, including ties
      # 寻找每个gt boxes与其iou最大的anchor索引，一个gt匹配到的最大iou可能有多个anchor
      # gt_pred_pairs_of_highest_quality = torch.nonzero(
      #     match_quality_matrix == highest_quality_foreach_gt[:, None]
      # )
      gt_pred_pairs_of_highest_quality = torch.where(
          torch.eq(
              match_quality_matrix, highest_quality_foreach_gt[:, None]
          )
      )
      # Example gt_pred_pairs_of_highest_quality:
      #   tensor([[    0, 39796],
      #           [    1, 32055],
      #           [    1, 32070],
      #           [    2, 39190],
      #           [    2, 40255],
      #           [    3, 40390],
      #           [    3, 41455],
      #           [    4, 45470],
      #           [    5, 45325],
      #           [    5, 46390]])
      # Each row is a (gt index, prediction index)
      # Note how gt items 1, 2, 3, and 5 each have two ties
  
      # gt_pred_pairs_of_highest_quality[:, 0]代表是对应的gt index(不需要)
      # pre_inds_to_update = gt_pred_pairs_of_highest_quality[:, 1]
      pre_inds_to_update = gt_pred_pairs_of_highest_quality[1]
      # 保留该anchor匹配gt最大iou的索引，即使iou低于设定的阈值
      matches[pre_inds_to_update] = all_matches[pre_inds_to_update]
  
imports: import torch
  import math
  from typing import List, Tuple
  from torch import Tensor
label_desc: Use image node_id 3 for calling the Matcher obj's underlying member method code with example usage: obj.set_low_quality_matches_(matches, all_matches, match_quality_matrix) without return types