class_docstr: Appearance-Free Link method.
  
  This method is proposed in
  "StrongSORT: Make DeepSORT Great Again"
  `StrongSORT<https://arxiv.org/abs/2202.13514>`_.
  
  Args:
      checkpoint (str): Checkpoint path.
      temporal_threshold (tuple, optional): The temporal constraint
          for tracklets association. Defaults to (0, 30).
      spatial_threshold (int, optional): The spatial constraint for
          tracklets association. Defaults to 75.
      confidence_threshold (float, optional): The minimum confidence
          threshold for tracklets association. Defaults to 0.95.
class_docstr_tok: ["Appearance-Free","Link","method",".","This","method","is","proposed","in","''","StrongSORT",":","Make","DeepSORT","Great","Again","''","`","StrongSORT","<","https",":","\/\/arxiv.org\/abs\/2202.13514",">","`","_",".","Args",":","checkpoint","(","str",")",":","Checkpoint","path",".","temporal_threshold","(","tuple",",","optional",")",":","The","temporal","constraint","for","tracklets","association",".","Defaults","to","(","0",",","30",")",".","spatial_threshold","(","int",",","optional",")",":","The","spatial","constraint","for","tracklets","association",".","Defaults","to","75.","confidence_threshold","(","float",",","optional",")",":","The","minimum","confidence","threshold","for","tracklets","association",".","Defaults","to","0.95","."]
docstr: Forward function.
  
  pred_tracks (ndarray): With shape (N, 7). Each row denotes
      (frame_id, track_id, x1, y1, x2, y2, score).
  
  Returns:
      ndarray: The linked tracks with shape (N, 7). Each row denotes
          (frame_id, track_id, x1, y1, x2, y2, score)
docstr_tok: ["Forward","function",".","pred_tracks","(","ndarray",")",":","With","shape","(","N",",","7",")",".","Each","row","denotes","(","frame_id",",","track_id",",","x1",",","y1",",","x2",",","y2",",","score",")",".","Returns",":","ndarray",":","The","linked","tracks","with","shape","(","N",",","7",")",".","Each","row","denotes","(","frame_id",",","track_id",",","x1",",","y1",",","x2",",","y2",",","score",")"]
code: def forward(self, pred_tracks: np.ndarray) -> np.ndarray:
      """Forward function.
  
      pred_tracks (ndarray): With shape (N, 7). Each row denotes
          (frame_id, track_id, x1, y1, x2, y2, score).
  
      Returns:
          ndarray: The linked tracks with shape (N, 7). Each row denotes
              (frame_id, track_id, x1, y1, x2, y2, score)
      """
      # sort tracks by the frame id
      pred_tracks = pred_tracks[np.argsort(pred_tracks[:, 0])]
  
      # gather tracks information
      id2info = defaultdict(list)
      for row in pred_tracks:
          frame_id, track_id, x1, y1, x2, y2 = row[:6]
          id2info[track_id].append([frame_id, x1, y1, x2 - x1, y2 - y1])
      id2info = {k: np.array(v) for k, v in id2info.items()}
      num_track = len(id2info)
      track_ids = np.array(list(id2info))
      cost_matrix = np.full((num_track, num_track), INFINITY)
  
      # compute the cost matrix
      for i, id_i in enumerate(track_ids):
          for j, id_j in enumerate(track_ids):
              if id_i == id_j:
                  continue
              info_i, info_j = id2info[id_i], id2info[id_j]
              frame_i, box_i = info_i[-1][0], info_i[-1][1:3]
              frame_j, box_j = info_j[0][0], info_j[0][1:3]
              # temporal constraint
              if (
                  not self.temporal_threshold[0]
                  <= frame_j - frame_i
                  <= self.temporal_threshold[1]
              ):
                  continue
              # spatial constraint
              if (
                  self.fn_l2(box_i[0] - box_j[0], box_i[1] - box_j[1])
                  > self.spatial_threshold
              ):
                  continue
              # confidence constraint
              track_i, track_j = self.data_transform(info_i, info_j)
  
              # numpy to torch
              track_i = torch.tensor(track_i, dtype=torch.float).to(
                  self.device
              )
              track_j = torch.tensor(track_j, dtype=torch.float).to(
                  self.device
              )
              track_i = track_i.unsqueeze(0).unsqueeze(0)
              track_j = track_j.unsqueeze(0).unsqueeze(0)
  
              confidence = (
                  self.model(track_i, track_j).detach().cpu().numpy()
              )
              if confidence >= self.confidence_threshold:
                  cost_matrix[i, j] = 1 - confidence
  
      # linear assignment
      indices = linear_sum_assignment(cost_matrix)
      _id2id = dict()  # the temporary assignment results
      id2id = dict()  # the final assignment results
      for i, j in zip(indices[0], indices[1]):
          if cost_matrix[i, j] < INFINITY:
              _id2id[i] = j
      for k, v in _id2id.items():
          if k in id2id:
              id2id[v] = id2id[k]
          else:
              id2id[v] = k
  
      # link
      for k, v in id2id.items():
          pred_tracks[pred_tracks[:, 1] == k, 1] = v
  
      # deduplicate
      _, index = np.unique(
          pred_tracks[:, :2], return_index=True, axis=0
      )
  
      return pred_tracks[index]
  
imports: from collections import defaultdict
  from typing import Tuple
  import numpy
  import torch
  from mmengine.model import BaseModule
  from mmengine.runner.checkpoint import load_checkpoint
  from scipy.optimize import linear_sum_assignment
  from torch import Tensor, nn
  from mmdet.registry import TASK_UTILS
label_desc: Use image node_id 3 for calling the AppearanceFreeLink obj's underlying member method code with example usage: obj.forward(pred_tracks) and returns: pred_tracks