youtube_vis.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. # flake8: noqa
  2. # pyre-unsafe
  3. # note: this file has been modified from its original version in TrackEval in
  4. # https://github.com/JonathonLuiten/TrackEval/blob/master/trackeval/datasets/youtube_vis.py
  5. # to support the following:
  6. # 1) bbox evaluation (via `IOU_TYPE`)
  7. # 2) passing GT and prediction data as Python objects (via `GT_JSON_OBJECT` and `TRACKER_JSON_OBJECT`)
  8. # 3) specifying a custom dataset name (via `DATASET_NAME`)
  9. import json
  10. import os
  11. import numpy as np
  12. from .. import _timing, utils
  13. from ..utils import TrackEvalException
  14. from ._base_dataset import _BaseDataset
  15. class YouTubeVIS(_BaseDataset):
  16. """Dataset class for YouTubeVIS tracking"""
  17. @staticmethod
  18. def get_default_dataset_config():
  19. """Default class config values"""
  20. code_path = utils.get_code_path()
  21. default_config = {
  22. "GT_FOLDER": os.path.join(
  23. code_path, "data/gt/youtube_vis/"
  24. ), # Location of GT data
  25. "TRACKERS_FOLDER": os.path.join(code_path, "data/trackers/youtube_vis/"),
  26. # Trackers location
  27. "OUTPUT_FOLDER": None, # Where to save eval results (if None, same as TRACKERS_FOLDER)
  28. "TRACKERS_TO_EVAL": None, # Filenames of trackers to eval (if None, all in folder)
  29. "CLASSES_TO_EVAL": None, # Classes to eval (if None, all classes)
  30. "SPLIT_TO_EVAL": "train_sub_split", # Valid: 'train', 'val', 'train_sub_split'
  31. "PRINT_CONFIG": True, # Whether to print current config
  32. "OUTPUT_SUB_FOLDER": "", # Output files are saved in OUTPUT_FOLDER/tracker_name/OUTPUT_SUB_FOLDER
  33. "TRACKER_SUB_FOLDER": "data", # Tracker files are in TRACKER_FOLDER/tracker_name/TRACKER_SUB_FOLDER
  34. "TRACKER_DISPLAY_NAMES": None, # Names of trackers to display, if None: TRACKERS_TO_EVAL
  35. # Added for video phrase AP evaluation -- allow directly specifying the GT JSON data and Tracker (result)
  36. # JSON data as Python objects, without reading from files.
  37. "GT_JSON_OBJECT": None,
  38. "TRACKER_JSON_OBJECT": None,
  39. "IOU_TYPE": "segm",
  40. "DATASET_NAME": "video",
  41. }
  42. return default_config
  43. def __init__(self, config=None):
  44. """Initialise dataset, checking that all required files are present"""
  45. super().__init__()
  46. # Fill non-given config values with defaults
  47. self.config = utils.init_config(config, self.get_default_dataset_config())
  48. self.gt_fol = (
  49. self.config["GT_FOLDER"] + "youtube_vis_" + self.config["SPLIT_TO_EVAL"]
  50. )
  51. self.tracker_fol = (
  52. self.config["TRACKERS_FOLDER"]
  53. + "youtube_vis_"
  54. + self.config["SPLIT_TO_EVAL"]
  55. )
  56. self.use_super_categories = False
  57. self.should_classes_combine = True
  58. assert self.config["IOU_TYPE"] in ["segm", "bbox"]
  59. self.iou_type = self.config["IOU_TYPE"]
  60. print("=" * 100)
  61. print(f"Evaluate annotation type *{self.iou_type}*")
  62. self.dataset_name = self.config["DATASET_NAME"]
  63. self.output_fol = self.config["OUTPUT_FOLDER"]
  64. if self.output_fol is None:
  65. self.output_fol = self.tracker_fol
  66. self.output_sub_fol = self.config["OUTPUT_SUB_FOLDER"]
  67. self.tracker_sub_fol = self.config["TRACKER_SUB_FOLDER"]
  68. if self.config["GT_JSON_OBJECT"] is not None:
  69. # allow directly specifying the GT JSON data without reading from files
  70. gt_json = self.config["GT_JSON_OBJECT"]
  71. assert isinstance(gt_json, dict)
  72. assert "videos" in gt_json
  73. assert "categories" in gt_json
  74. assert "annotations" in gt_json
  75. self.gt_data = gt_json
  76. else:
  77. if not os.path.exists(self.gt_fol):
  78. print("GT folder not found: " + self.gt_fol)
  79. raise TrackEvalException(
  80. "GT folder not found: " + os.path.basename(self.gt_fol)
  81. )
  82. gt_dir_files = [
  83. file for file in os.listdir(self.gt_fol) if file.endswith(".json")
  84. ]
  85. if len(gt_dir_files) != 1:
  86. raise TrackEvalException(
  87. self.gt_fol + " does not contain exactly one json file."
  88. )
  89. with open(os.path.join(self.gt_fol, gt_dir_files[0])) as f:
  90. self.gt_data = json.load(f)
  91. # Get classes to eval
  92. self.valid_classes = [cls["name"] for cls in self.gt_data["categories"]]
  93. cls_name_to_cls_id_map = {
  94. cls["name"]: cls["id"] for cls in self.gt_data["categories"]
  95. }
  96. if self.config["CLASSES_TO_EVAL"]:
  97. self.class_list = [
  98. cls.lower() if cls.lower() in self.valid_classes else None
  99. for cls in self.config["CLASSES_TO_EVAL"]
  100. ]
  101. if not all(self.class_list):
  102. raise TrackEvalException(
  103. "Attempted to evaluate an invalid class. Only classes "
  104. + ", ".join(self.valid_classes)
  105. + " are valid."
  106. )
  107. else:
  108. self.class_list = [cls["name"] for cls in self.gt_data["categories"]]
  109. self.class_name_to_class_id = {
  110. k: v for k, v in cls_name_to_cls_id_map.items() if k in self.class_list
  111. }
  112. # Get sequences to eval and check gt files exist
  113. self.seq_list = [
  114. vid["file_names"][0].split("/")[0] for vid in self.gt_data["videos"]
  115. ]
  116. self.seq_name_to_seq_id = {
  117. vid["file_names"][0].split("/")[0]: vid["id"]
  118. for vid in self.gt_data["videos"]
  119. }
  120. self.seq_lengths = {
  121. vid["id"]: len(vid["file_names"]) for vid in self.gt_data["videos"]
  122. }
  123. # encode masks and compute track areas
  124. self._prepare_gt_annotations()
  125. # Get trackers to eval
  126. if self.config["TRACKER_JSON_OBJECT"] is not None:
  127. # allow directly specifying the tracker JSON data without reading from files
  128. tracker_json = self.config["TRACKER_JSON_OBJECT"]
  129. assert isinstance(tracker_json, list)
  130. self.tracker_list = ["tracker"]
  131. elif self.config["TRACKERS_TO_EVAL"] is None:
  132. self.tracker_list = os.listdir(self.tracker_fol)
  133. else:
  134. self.tracker_list = self.config["TRACKERS_TO_EVAL"]
  135. if self.config["TRACKER_DISPLAY_NAMES"] is None:
  136. self.tracker_to_disp = dict(zip(self.tracker_list, self.tracker_list))
  137. elif (self.config["TRACKERS_TO_EVAL"] is not None) and (
  138. len(self.config["TRACKER_DISPLAY_NAMES"]) == len(self.tracker_list)
  139. ):
  140. self.tracker_to_disp = dict(
  141. zip(self.tracker_list, self.config["TRACKER_DISPLAY_NAMES"])
  142. )
  143. else:
  144. raise TrackEvalException(
  145. "List of tracker files and tracker display names do not match."
  146. )
  147. # counter for globally unique track IDs
  148. self.global_tid_counter = 0
  149. self.tracker_data = dict()
  150. if self.config["TRACKER_JSON_OBJECT"] is not None:
  151. # allow directly specifying the tracker JSON data without reading from files
  152. tracker = self.tracker_list[0]
  153. self.tracker_data[tracker] = tracker_json
  154. else:
  155. for tracker in self.tracker_list:
  156. tracker_dir_path = os.path.join(
  157. self.tracker_fol, tracker, self.tracker_sub_fol
  158. )
  159. tr_dir_files = [
  160. file
  161. for file in os.listdir(tracker_dir_path)
  162. if file.endswith(".json")
  163. ]
  164. if len(tr_dir_files) != 1:
  165. raise TrackEvalException(
  166. tracker_dir_path + " does not contain exactly one json file."
  167. )
  168. with open(os.path.join(tracker_dir_path, tr_dir_files[0])) as f:
  169. curr_data = json.load(f)
  170. self.tracker_data[tracker] = curr_data
  171. def get_display_name(self, tracker):
  172. return self.tracker_to_disp[tracker]
  173. def _load_raw_file(self, tracker, seq, is_gt):
  174. """Load a file (gt or tracker) in the YouTubeVIS format
  175. If is_gt, this returns a dict which contains the fields:
  176. [gt_ids, gt_classes] : list (for each timestep) of 1D NDArrays (for each det).
  177. [gt_dets]: list (for each timestep) of lists of detections.
  178. [classes_to_gt_tracks]: dictionary with class values as keys and list of dictionaries (with frame indices as
  179. keys and corresponding segmentations as values) for each track
  180. [classes_to_gt_track_ids, classes_to_gt_track_areas, classes_to_gt_track_iscrowd]: dictionary with class values
  181. as keys and lists (for each track) as values
  182. if not is_gt, this returns a dict which contains the fields:
  183. [tracker_ids, tracker_classes, tracker_confidences] : list (for each timestep) of 1D NDArrays (for each det).
  184. [tracker_dets]: list (for each timestep) of lists of detections.
  185. [classes_to_dt_tracks]: dictionary with class values as keys and list of dictionaries (with frame indices as
  186. keys and corresponding segmentations as values) for each track
  187. [classes_to_dt_track_ids, classes_to_dt_track_areas]: dictionary with class values as keys and lists as values
  188. [classes_to_dt_track_scores]: dictionary with class values as keys and 1D numpy arrays as values
  189. """
  190. # select sequence tracks
  191. seq_id = self.seq_name_to_seq_id[seq]
  192. if is_gt:
  193. tracks = [
  194. ann for ann in self.gt_data["annotations"] if ann["video_id"] == seq_id
  195. ]
  196. else:
  197. tracks = self._get_tracker_seq_tracks(tracker, seq_id)
  198. # Convert data to required format
  199. num_timesteps = self.seq_lengths[seq_id]
  200. data_keys = ["ids", "classes", "dets"]
  201. if not is_gt:
  202. data_keys += ["tracker_confidences"]
  203. raw_data = {key: [None] * num_timesteps for key in data_keys}
  204. result_key = "segmentations" if self.iou_type == "segm" else "bboxes"
  205. for t in range(num_timesteps):
  206. raw_data["dets"][t] = [
  207. track[result_key][t] for track in tracks if track[result_key][t]
  208. ]
  209. raw_data["ids"][t] = np.atleast_1d(
  210. [track["id"] for track in tracks if track[result_key][t]]
  211. ).astype(int)
  212. raw_data["classes"][t] = np.atleast_1d(
  213. [track["category_id"] for track in tracks if track[result_key][t]]
  214. ).astype(int)
  215. if not is_gt:
  216. raw_data["tracker_confidences"][t] = np.atleast_1d(
  217. [track["score"] for track in tracks if track[result_key][t]]
  218. ).astype(float)
  219. if is_gt:
  220. key_map = {"ids": "gt_ids", "classes": "gt_classes", "dets": "gt_dets"}
  221. else:
  222. key_map = {
  223. "ids": "tracker_ids",
  224. "classes": "tracker_classes",
  225. "dets": "tracker_dets",
  226. }
  227. for k, v in key_map.items():
  228. raw_data[v] = raw_data.pop(k)
  229. all_cls_ids = {self.class_name_to_class_id[cls] for cls in self.class_list}
  230. classes_to_tracks = {
  231. cls: [track for track in tracks if track["category_id"] == cls]
  232. for cls in all_cls_ids
  233. }
  234. # mapping from classes to track representations and track information
  235. raw_data["classes_to_tracks"] = {
  236. cls: [
  237. {i: track[result_key][i] for i in range(len(track[result_key]))}
  238. for track in tracks
  239. ]
  240. for cls, tracks in classes_to_tracks.items()
  241. }
  242. raw_data["classes_to_track_ids"] = {
  243. cls: [track["id"] for track in tracks]
  244. for cls, tracks in classes_to_tracks.items()
  245. }
  246. raw_data["classes_to_track_areas"] = {
  247. cls: [track["area"] for track in tracks]
  248. for cls, tracks in classes_to_tracks.items()
  249. }
  250. if is_gt:
  251. raw_data["classes_to_gt_track_iscrowd"] = {
  252. cls: [track["iscrowd"] for track in tracks]
  253. for cls, tracks in classes_to_tracks.items()
  254. }
  255. else:
  256. raw_data["classes_to_dt_track_scores"] = {
  257. cls: np.array([track["score"] for track in tracks])
  258. for cls, tracks in classes_to_tracks.items()
  259. }
  260. if is_gt:
  261. key_map = {
  262. "classes_to_tracks": "classes_to_gt_tracks",
  263. "classes_to_track_ids": "classes_to_gt_track_ids",
  264. "classes_to_track_areas": "classes_to_gt_track_areas",
  265. }
  266. else:
  267. key_map = {
  268. "classes_to_tracks": "classes_to_dt_tracks",
  269. "classes_to_track_ids": "classes_to_dt_track_ids",
  270. "classes_to_track_areas": "classes_to_dt_track_areas",
  271. }
  272. for k, v in key_map.items():
  273. raw_data[v] = raw_data.pop(k)
  274. raw_data["num_timesteps"] = num_timesteps
  275. raw_data["seq"] = seq
  276. return raw_data
  277. @_timing.time
  278. def get_preprocessed_seq_data(self, raw_data, cls):
  279. """Preprocess data for a single sequence for a single class ready for evaluation.
  280. Inputs:
  281. - raw_data is a dict containing the data for the sequence already read in by get_raw_seq_data().
  282. - cls is the class to be evaluated.
  283. Outputs:
  284. - data is a dict containing all of the information that metrics need to perform evaluation.
  285. It contains the following fields:
  286. [num_timesteps, num_gt_ids, num_tracker_ids, num_gt_dets, num_tracker_dets] : integers.
  287. [gt_ids, tracker_ids, tracker_confidences]: list (for each timestep) of 1D NDArrays (for each det).
  288. [gt_dets, tracker_dets]: list (for each timestep) of lists of detections.
  289. [similarity_scores]: list (for each timestep) of 2D NDArrays.
  290. Notes:
  291. General preprocessing (preproc) occurs in 4 steps. Some datasets may not use all of these steps.
  292. 1) Extract only detections relevant for the class to be evaluated (including distractor detections).
  293. 2) Match gt dets and tracker dets. Remove tracker dets that are matched to a gt det that is of a
  294. distractor class, or otherwise marked as to be removed.
  295. 3) Remove unmatched tracker dets if they fall within a crowd ignore region or don't meet a certain
  296. other criteria (e.g. are too small).
  297. 4) Remove gt dets that were only useful for preprocessing and not for actual evaluation.
  298. After the above preprocessing steps, this function also calculates the number of gt and tracker detections
  299. and unique track ids. It also relabels gt and tracker ids to be contiguous and checks that ids are
  300. unique within each timestep.
  301. YouTubeVIS:
  302. In YouTubeVIS, the 4 preproc steps are as follow:
  303. 1) There are 40 classes which are evaluated separately.
  304. 2) No matched tracker dets are removed.
  305. 3) No unmatched tracker dets are removed.
  306. 4) No gt dets are removed.
  307. Further, for TrackMAP computation track representations for the given class are accessed from a dictionary
  308. and the tracks from the tracker data are sorted according to the tracker confidence.
  309. """
  310. cls_id = self.class_name_to_class_id[cls]
  311. data_keys = [
  312. "gt_ids",
  313. "tracker_ids",
  314. "gt_dets",
  315. "tracker_dets",
  316. "similarity_scores",
  317. ]
  318. data = {key: [None] * raw_data["num_timesteps"] for key in data_keys}
  319. unique_gt_ids = []
  320. unique_tracker_ids = []
  321. num_gt_dets = 0
  322. num_tracker_dets = 0
  323. for t in range(raw_data["num_timesteps"]):
  324. # Only extract relevant dets for this class for eval (cls)
  325. gt_class_mask = np.atleast_1d(raw_data["gt_classes"][t] == cls_id)
  326. gt_class_mask = gt_class_mask.astype(bool)
  327. gt_ids = raw_data["gt_ids"][t][gt_class_mask]
  328. gt_dets = [
  329. raw_data["gt_dets"][t][ind]
  330. for ind in range(len(gt_class_mask))
  331. if gt_class_mask[ind]
  332. ]
  333. tracker_class_mask = np.atleast_1d(raw_data["tracker_classes"][t] == cls_id)
  334. tracker_class_mask = tracker_class_mask.astype(bool)
  335. tracker_ids = raw_data["tracker_ids"][t][tracker_class_mask]
  336. tracker_dets = [
  337. raw_data["tracker_dets"][t][ind]
  338. for ind in range(len(tracker_class_mask))
  339. if tracker_class_mask[ind]
  340. ]
  341. similarity_scores = raw_data["similarity_scores"][t][gt_class_mask, :][
  342. :, tracker_class_mask
  343. ]
  344. data["tracker_ids"][t] = tracker_ids
  345. data["tracker_dets"][t] = tracker_dets
  346. data["gt_ids"][t] = gt_ids
  347. data["gt_dets"][t] = gt_dets
  348. data["similarity_scores"][t] = similarity_scores
  349. unique_gt_ids += list(np.unique(data["gt_ids"][t]))
  350. unique_tracker_ids += list(np.unique(data["tracker_ids"][t]))
  351. num_tracker_dets += len(data["tracker_ids"][t])
  352. num_gt_dets += len(data["gt_ids"][t])
  353. # Re-label IDs such that there are no empty IDs
  354. if len(unique_gt_ids) > 0:
  355. unique_gt_ids = np.unique(unique_gt_ids)
  356. gt_id_map = np.nan * np.ones((np.max(unique_gt_ids) + 1))
  357. gt_id_map[unique_gt_ids] = np.arange(len(unique_gt_ids))
  358. for t in range(raw_data["num_timesteps"]):
  359. if len(data["gt_ids"][t]) > 0:
  360. data["gt_ids"][t] = gt_id_map[data["gt_ids"][t]].astype(int)
  361. if len(unique_tracker_ids) > 0:
  362. unique_tracker_ids = np.unique(unique_tracker_ids)
  363. tracker_id_map = np.nan * np.ones((np.max(unique_tracker_ids) + 1))
  364. tracker_id_map[unique_tracker_ids] = np.arange(len(unique_tracker_ids))
  365. for t in range(raw_data["num_timesteps"]):
  366. if len(data["tracker_ids"][t]) > 0:
  367. data["tracker_ids"][t] = tracker_id_map[
  368. data["tracker_ids"][t]
  369. ].astype(int)
  370. # Ensure that ids are unique per timestep.
  371. self._check_unique_ids(data)
  372. # Record overview statistics.
  373. data["num_tracker_dets"] = num_tracker_dets
  374. data["num_gt_dets"] = num_gt_dets
  375. data["num_tracker_ids"] = len(unique_tracker_ids)
  376. data["num_gt_ids"] = len(unique_gt_ids)
  377. data["num_timesteps"] = raw_data["num_timesteps"]
  378. data["seq"] = raw_data["seq"]
  379. # get track representations
  380. data["gt_tracks"] = raw_data["classes_to_gt_tracks"][cls_id]
  381. data["gt_track_ids"] = raw_data["classes_to_gt_track_ids"][cls_id]
  382. data["gt_track_areas"] = raw_data["classes_to_gt_track_areas"][cls_id]
  383. data["gt_track_iscrowd"] = raw_data["classes_to_gt_track_iscrowd"][cls_id]
  384. data["dt_tracks"] = raw_data["classes_to_dt_tracks"][cls_id]
  385. data["dt_track_ids"] = raw_data["classes_to_dt_track_ids"][cls_id]
  386. data["dt_track_areas"] = raw_data["classes_to_dt_track_areas"][cls_id]
  387. data["dt_track_scores"] = raw_data["classes_to_dt_track_scores"][cls_id]
  388. data["iou_type"] = "mask"
  389. # sort tracker data tracks by tracker confidence scores
  390. if data["dt_tracks"]:
  391. idx = np.argsort(
  392. [-score for score in data["dt_track_scores"]], kind="mergesort"
  393. )
  394. data["dt_track_scores"] = [data["dt_track_scores"][i] for i in idx]
  395. data["dt_tracks"] = [data["dt_tracks"][i] for i in idx]
  396. data["dt_track_ids"] = [data["dt_track_ids"][i] for i in idx]
  397. data["dt_track_areas"] = [data["dt_track_areas"][i] for i in idx]
  398. return data
  399. def _calculate_similarities(self, gt_dets_t, tracker_dets_t):
  400. if self.iou_type == "segm":
  401. similarity_scores = self._calculate_mask_ious(
  402. gt_dets_t, tracker_dets_t, is_encoded=True, do_ioa=False
  403. )
  404. else:
  405. gt_dets_t = np.array(gt_dets_t, dtype=np.float32).reshape(-1, 4)
  406. tracker_dets_t = np.array(tracker_dets_t, dtype=np.float32).reshape(-1, 4)
  407. similarity_scores = self._calculate_box_ious(
  408. gt_dets_t, tracker_dets_t, box_format="xywh", do_ioa=False
  409. )
  410. return similarity_scores
  411. def _prepare_gt_annotations(self):
  412. """
  413. Prepares GT data by rle encoding segmentations and computing the average track area.
  414. :return: None
  415. """
  416. if self.iou_type == "segm":
  417. # only loaded when needed to reduce minimum requirements
  418. from pycocotools import mask as mask_utils
  419. for track in self.gt_data["annotations"]:
  420. h = track["height"]
  421. w = track["width"]
  422. for i, seg in enumerate(track["segmentations"]):
  423. if seg is not None and isinstance(seg["counts"], list):
  424. track["segmentations"][i] = mask_utils.frPyObjects(seg, h, w)
  425. areas = [a for a in track["areas"] if a]
  426. if len(areas) == 0:
  427. track["area"] = 0
  428. else:
  429. track["area"] = np.array(areas).mean()
  430. else:
  431. for track in self.gt_data["annotations"]:
  432. # For bbox eval, compute areas from bboxes if not already available
  433. areas = [a for a in track.get("areas", []) if a]
  434. if not areas:
  435. areas = []
  436. for bbox in track.get("bboxes", []):
  437. if bbox is not None:
  438. areas.append(bbox[2] * bbox[3])
  439. track["area"] = np.array(areas).mean() if areas else 0
  440. def _get_tracker_seq_tracks(self, tracker, seq_id):
  441. """
  442. Prepares tracker data for a given sequence. Extracts all annotations for given sequence ID, computes
  443. average track area and assigns a track ID.
  444. :param tracker: the given tracker
  445. :param seq_id: the sequence ID
  446. :return: the extracted tracks
  447. """
  448. # only loaded when needed to reduce minimum requirements
  449. from pycocotools import mask as mask_utils
  450. tracks = [
  451. ann for ann in self.tracker_data[tracker] if ann["video_id"] == seq_id
  452. ]
  453. for track in tracks:
  454. if "areas" not in track:
  455. if self.iou_type == "segm":
  456. for seg in track["segmentations"]:
  457. if seg:
  458. track["areas"].append(mask_utils.area(seg))
  459. else:
  460. track["areas"].append(None)
  461. else:
  462. for bbox in track["bboxes"]:
  463. if bbox:
  464. track["areas"].append(bbox[2] * bbox[3])
  465. else:
  466. track["areas"].append(None)
  467. areas = [a for a in track["areas"] if a]
  468. if len(areas) == 0:
  469. track["area"] = 0
  470. else:
  471. track["area"] = np.array(areas).mean()
  472. track["id"] = self.global_tid_counter
  473. self.global_tid_counter += 1
  474. return tracks
  475. def get_name(self):
  476. return self.dataset_name