class_docstr: Args:
      model_dir (str): root path of model.pdiparams, model.pdmodel and infer_cfg.yml
      tracker_config (str): tracker config path
      device (str): Choose the device you want to run, it can be: CPU/GPU/XPU/NPU, default is CPU
      run_mode (str): mode of running(paddle/trt_fp32/trt_fp16)
      batch_size (int): size of pre batch in inference
      trt_min_shape (int): min shape for dynamic shape in trt
      trt_max_shape (int): max shape for dynamic shape in trt
      trt_opt_shape (int): opt shape for dynamic shape in trt
      trt_calib_mode (bool): If the model is produced by TRT offline quantitative
          calibration, trt_calib_mode need to set True
      cpu_threads (int): cpu threads
      enable_mkldnn (bool): whether to open MKLDNN
      output_dir (string): The path of output, default as 'output'
      threshold (float): Score threshold of the detected bbox, default as 0.5
      save_images (bool): Whether to save visualization image results, default as False
      save_mot_txts (bool): Whether to save tracking results (txt), default as False
      draw_center_traj (bool): Whether drawing the trajectory of center, default as False
      secs_interval (int): The seconds interval to count after tracking, default as 10
      skip_frame_num (int): Skip frame num to get faster MOT results, default as -1
      warmup_frame (int):Warmup frame num to test speed of MOT,default as 50
      do_entrance_counting(bool): Whether counting the numbers of identifiers entering 
          or getting out from the entrance, default as False，only support single class
          counting in MOT, and the video should be taken by a static camera.
      do_break_in_counting(bool): Whether counting the numbers of identifiers break in
          the area, default as False，only support single class counting in MOT,
          and the video should be taken by a static camera.
      region_type (str): Area type for entrance counting or break in counting, 'horizontal'
          and 'vertical' used when do entrance counting. 'custom' used when do break in counting. 
          Note that only support single-class MOT, and the video should be taken by a static camera.
      region_polygon (list): Clockwise point coords (x0,y0,x1,y1...) of polygon of area when
          do_break_in_counting. Note that only support single-class MOT and
          the video should be taken by a static camera.
      reid_model_dir (str): reid model dir, default None for ByteTrack, but set for DeepSORT
      mtmct_dir (str): MTMCT dir, default None, set for doing MTMCT
class_docstr_tok: ["Args",":","model_dir","(","str",")",":","root","path","of","model.pdiparams",",","model.pdmodel","and","infer_cfg.yml","tracker_config","(","str",")",":","tracker","config","path","device","(","str",")",":","Choose","the","device","you","want","to","run",",","it","can","be",":","CPU\/GPU\/XPU\/NPU",",","default","is","CPU","run_mode","(","str",")",":","mode","of","running","(","paddle\/trt_fp32\/trt_fp16",")","batch_size","(","int",")",":","size","of","pre","batch","in","inference","trt_min_shape","(","int",")",":","min","shape","for","dynamic","shape","in","trt","trt_max_shape","(","int",")",":","max","shape","for","dynamic","shape","in","trt","trt_opt_shape","(","int",")",":","opt","shape","for","dynamic","shape","in","trt","trt_calib_mode","(","bool",")",":","If","the","model","is","produced","by","TRT","offline","quantitative","calibration",",","trt_calib_mode","need","to","set","True","cpu_threads","(","int",")",":","cpu","threads","enable_mkldnn","(","bool",")",":","whether","to","open","MKLDNN","output_dir","(","string",")",":","The","path","of","output",",","default","as","'output'","threshold","(","float",")",":","Score","threshold","of","the","detected","bbox",",","default","as","0.5","save_images","(","bool",")",":","Whether","to","save","visualization","image","results",",","default","as","False","save_mot_txts","(","bool",")",":","Whether","to","save","tracking","results","(","txt",")",",","default","as","False","draw_center_traj","(","bool",")",":","Whether","drawing","the","trajectory","of","center",",","default","as","False","secs_interval","(","int",")",":","The","seconds","interval","to","count","after","tracking",",","default","as","10","skip_frame_num","(","int",")",":","Skip","frame","num","to","get","faster","MOT","results",",","default","as","-1","warmup_frame","(","int",")",":","Warmup","frame","num","to","test","speed","of","MOT",",","default","as","50","do_entrance_counting","(","bool",")",":","Whether","counting","the","numbers","of","identifiers","entering","or","getting","out","from","the","entrance",",","default","as","False\uff0conly","support","single","class","counting","in","MOT",",","and","the","video","should","be","taken","by","a","static","camera",".","do_break_in_counting","(","bool",")",":","Whether","counting","the","numbers","of","identifiers","break","in","the","area",",","default","as","False\uff0conly","support","single","class","counting","in","MOT",",","and","the","video","should","be","taken","by","a","static","camera",".","region_type","(","str",")",":","Area","type","for","entrance","counting","or","break","in","counting",",","'horizontal'","and","'vertical","'","used","when","do","entrance","counting",".","'custom","'","used","when","do","break","in","counting",".","Note","that","only","support","single-class","MOT",",","and","the","video","should","be","taken","by","a","static","camera",".","region_polygon","(","list",")",":","Clockwise","point","coords","(","x0",",","y0",",","x1",",","y1","...",")","of","polygon","of","area","when","do_break_in_counting",".","Note","that","only","support","single-class","MOT","and","the","video","should","be","taken","by","a","static","camera",".","reid_model_dir","(","str",")",":","reid","model","dir",",","default","None","for","ByteTrack",",","but","set","for","DeepSORT","mtmct_dir","(","str",")",":","MTMCT","dir",",","default","None",",","set","for","doing","MTMCT"]
code: def tracking(self, det_results, img=None):
      pred_dets = det_results["boxes"]  # cls_id, score, x0, y0, x1, y1
      pred_embs = det_results.get("embeddings", None)
  
      if self.use_deepsort_tracker:
          # use DeepSORTTracker, only support singe class
          self.tracker.predict()
          online_targets = self.tracker.update(pred_dets, pred_embs)
          online_tlwhs, online_scores, online_ids = [], [], []
          if self.do_mtmct:
              online_tlbrs, online_feats = [], []
          for t in online_targets:
              if not t.is_confirmed() or t.time_since_update > 1:
                  continue
              tlwh = t.to_tlwh()
              tscore = t.score
              tid = t.track_id
              if (
                  self.tracker.vertical_ratio > 0
                  and tlwh[2] / tlwh[3] > self.tracker.vertical_ratio
              ):
                  continue
              online_tlwhs.append(tlwh)
              online_scores.append(tscore)
              online_ids.append(tid)
              if self.do_mtmct:
                  online_tlbrs.append(t.to_tlbr())
                  online_feats.append(t.feat)
  
          tracking_outs = {
              "online_tlwhs": online_tlwhs,
              "online_scores": online_scores,
              "online_ids": online_ids,
          }
          if self.do_mtmct:
              seq_name = det_results["seq_name"]
              frame_id = det_results["frame_id"]
  
              tracking_outs["feat_data"] = {}
              for _tlbr, _id, _feat in zip(
                  online_tlbrs, online_ids, online_feats
              ):
                  feat_data = {}
                  feat_data["bbox"] = _tlbr
                  feat_data["frame"] = f"{frame_id:06d}"
                  feat_data["id"] = _id
                  _imgname = f"{seq_name}_{_id}_{frame_id}.jpg"
                  feat_data["imgname"] = _imgname
                  feat_data["feat"] = _feat
                  tracking_outs["feat_data"].update(
                      {_imgname: feat_data}
                  )
          return tracking_outs
  
      elif self.use_ocsort_tracker:
          # use OCSORTTracker, only support singe class
          online_targets = self.tracker.update(pred_dets, pred_embs)
          online_tlwhs = defaultdict(list)
          online_scores = defaultdict(list)
          online_ids = defaultdict(list)
          for t in online_targets:
              tlwh = [t[0], t[1], t[2] - t[0], t[3] - t[1]]
              tscore = float(t[4])
              tid = int(t[5])
              if tlwh[2] * tlwh[3] <= self.tracker.min_box_area:
                  continue
              if (
                  self.tracker.vertical_ratio > 0
                  and tlwh[2] / tlwh[3] > self.tracker.vertical_ratio
              ):
                  continue
              if tlwh[2] * tlwh[3] > 0:
                  online_tlwhs[0].append(tlwh)
                  online_ids[0].append(tid)
                  online_scores[0].append(tscore)
          tracking_outs = {
              "online_tlwhs": online_tlwhs,
              "online_scores": online_scores,
              "online_ids": online_ids,
          }
          return tracking_outs
  
      elif self.use_botsort_tracker:
          # use BOTSORTTracker, only support singe class
          online_targets = self.tracker.update(pred_dets, img)
          online_tlwhs = defaultdict(list)
          online_scores = defaultdict(list)
          online_ids = defaultdict(list)
          for t in online_targets:
              tlwh = t.tlwh
              tid = t.track_id
              tscore = t.score
              if tlwh[2] * tlwh[3] <= self.tracker.min_box_area:
                  continue
              online_tlwhs[0].append(tlwh)
              online_ids[0].append(tid)
              online_scores[0].append(tscore)
  
          tracking_outs = {
              "online_tlwhs": online_tlwhs,
              "online_scores": online_scores,
              "online_ids": online_ids,
          }
          return tracking_outs
  
      else:
          # use ByteTracker, support multiple class
          online_tlwhs = defaultdict(list)
          online_scores = defaultdict(list)
          online_ids = defaultdict(list)
          if self.do_mtmct:
              online_tlbrs, online_feats = defaultdict(
                  list
              ), defaultdict(list)
          online_targets_dict = self.tracker.update(
              pred_dets, pred_embs
          )
          for cls_id in range(self.num_classes):
              online_targets = online_targets_dict[cls_id]
              for t in online_targets:
                  tlwh = t.tlwh
                  tid = t.track_id
                  tscore = t.score
                  if tlwh[2] * tlwh[3] <= self.tracker.min_box_area:
                      continue
                  if (
                      self.tracker.vertical_ratio > 0
                      and tlwh[2] / tlwh[3]
                      > self.tracker.vertical_ratio
                  ):
                      continue
                  online_tlwhs[cls_id].append(tlwh)
                  online_ids[cls_id].append(tid)
                  online_scores[cls_id].append(tscore)
                  if self.do_mtmct:
                      online_tlbrs[cls_id].append(t.tlbr)
                      online_feats[cls_id].append(t.curr_feat)
  
          if self.do_mtmct:
              assert (
                  self.num_classes == 1
              ), "MTMCT only support single class."
              tracking_outs = {
                  "online_tlwhs": online_tlwhs[0],
                  "online_scores": online_scores[0],
                  "online_ids": online_ids[0],
              }
              seq_name = det_results["seq_name"]
              frame_id = det_results["frame_id"]
              tracking_outs["feat_data"] = {}
              for _tlbr, _id, _feat in zip(
                  online_tlbrs[0], online_ids[0], online_feats[0]
              ):
                  feat_data = {}
                  feat_data["bbox"] = _tlbr
                  feat_data["frame"] = f"{frame_id:06d}"
                  feat_data["id"] = _id
                  _imgname = f"{seq_name}_{_id}_{frame_id}.jpg"
                  feat_data["imgname"] = _imgname
                  feat_data["feat"] = _feat
                  tracking_outs["feat_data"].update(
                      {_imgname: feat_data}
                  )
              return tracking_outs
  
          else:
              tracking_outs = {
                  "online_tlwhs": online_tlwhs,
                  "online_scores": online_scores,
                  "online_ids": online_ids,
              }
              return tracking_outs
  
imports: import os
  import time
  import yaml
  import cv2
  import re
  import glob
  import numpy
  from collections import defaultdict
  import paddle
  from benchmark_utils import PaddleInferBenchmark
  from preprocess import decode_image
  import sys
  from det_infer import Detector, get_test_images, print_arguments, bench_log, PredictConfig, load_predictor
  from mot_utils import argsparser, Timer, get_current_memory_mb, video2frames, _is_valid_video
  from mot.tracker import JDETracker, DeepSORTTracker, OCSORTTracker, BOTSORTTracker
  from mot.utils import MOTTimer, write_mot_results, get_crops, clip_box, flow_statistic
  from mot.visualize import plot_tracking, plot_tracking_dict
  from mot.mtmct.utils import parse_bias
  from mot.mtmct.postprocess import trajectory_fusion, sub_cluster, gen_res, print_mtmct_result
  from mot.mtmct.postprocess import get_mtmct_matching_results, save_mtmct_crops, save_mtmct_vis_results
label_desc: Use image node_id 4 for calling the SDE_Detector obj's underlying member method code with example usage: obj.tracking(det_results, img) and returns: tracking_outs, tracking_outs, tracking_outs, tracking_outs, tracking_outs