"""BDD100K tracking evaluator."""from__future__importannotationsfromvis4d.common.importsimportBDD100K_AVAILABLE,SCALABEL_AVAILABLEfromvis4d.common.typingimportMetricLogsfromvis4d.data.datasets.bdd100kimportbdd100k_track_mapfrom..scalabel.trackimportScalabelTrackEvaluatorifSCALABEL_AVAILABLEandBDD100K_AVAILABLE:frombdd100k.common.utilsimportload_bdd100k_configfrombdd100k.label.to_scalabelimportbdd100k_to_scalabelfromscalabel.eval.detectimportevaluate_detfromscalabel.eval.motimportacc_single_video_mot,evaluate_trackfromscalabel.label.ioimportgroup_and_sortelse:raiseImportError("scalabel or bdd100k is not installed.")
[docs]classBDD100KTrackEvaluator(ScalabelTrackEvaluator):"""BDD100K 2D tracking evaluation class."""METRICS_DET="Det"METRICS_TRACK="Track"def__init__(self,annotation_path:str,config_path:str="box_track",mask_threshold:float=0.0,)->None:"""Initialize the evaluator."""config=load_bdd100k_config(config_path)super().__init__(annotation_path=annotation_path,config=config.scalabel,mask_threshold=mask_threshold,)self.gt_frames=bdd100k_to_scalabel(self.gt_frames,config)self.inverse_cat_map={v:kfork,vinbdd100k_track_map.items()}
[docs]def__repr__(self)->str:"""Concise representation of the dataset evaluator."""return"BDD100K Tracking Evaluator"
[docs]defevaluate(self,metric:str)->tuple[MetricLogs,str]:"""Evaluate the dataset."""assertself.configisnotNone,"BDD100K config is not loaded."metrics_log:MetricLogs={}short_description=""ifmetric==self.METRICS_DET:det_results=evaluate_det(self.gt_frames,self.frames,config=self.config,nproc=0,)formetric_name,metric_valueindet_results.summary().items():metrics_log[metric_name]=metric_valueshort_description+=str(det_results)+"\n"ifmetric==self.METRICS_TRACK:track_results=evaluate_track(acc_single_video_mot,gts=group_and_sort(self.gt_frames),results=group_and_sort(self.frames),config=self.config,nproc=1,)formetric_name,metric_valueintrack_results.summary().items():metrics_log[metric_name]=metric_valueshort_description+=str(track_results)+"\n"returnmetrics_log,short_description