(hydra_cfg: DictConfig)
| 20 | |
| 21 | @hydra.main(version_base="1.2", config_path="../configs", config_name="eval") |
| 22 | def main(hydra_cfg: DictConfig): |
| 23 | # setup_debug(hydra_cfg.debug) |
| 24 | # OmegaConf.set_struct(hydra_cfg, False) |
| 25 | |
| 26 | logger = logging.getLogger("relpose-angle") |
| 27 | |
| 28 | all_eval_models: ListConfig = hydra_cfg.eval_models # see configs/evaluation/relpose-angular.yaml |
| 29 | all_eval_datasets: ListConfig = hydra_cfg.eval_datasets # see configs/evaluation/relpose-angular.yaml |
| 30 | all_data_info: DictConfig = hydra_cfg.data # see configs/data |
| 31 | all_model_info: DictConfig = hydra_cfg.model # see configs/model |
| 32 | |
| 33 | for idx_model, model_keyname in enumerate(all_eval_models, start=1): |
| 34 | # 0.1 look up model config from configs/model, decide the model name (to save) |
| 35 | if model_keyname not in all_model_info: |
| 36 | raise ValueError(f"Unknown model in global data information: {model_keyname}") |
| 37 | model_info = all_model_info[model_keyname] |
| 38 | |
| 39 | # 0.2 load the model |
| 40 | model = hydra.utils.instantiate(model_info.cfg).to(hydra_cfg.device) |
| 41 | logger.info(f"[{idx_model}/{len(all_eval_models)}] Loaded Model {model_keyname} from {model_info.cfg.pretrained_model_name_or_path if hasattr(model_info.cfg, 'pretrained_model_name_or_path') else '???'}") |
| 42 | |
| 43 | # 0.3 route the correct infer function for the model |
| 44 | # output_root = osp.join(hydra_cfg.log.output_dir, model_name) |
| 45 | infer_func_cfg = model_info.get( |
| 46 | "infer_cameras_w2c", |
| 47 | DictConfig({ |
| 48 | '_target_': f'interfaces.{model_keyname}.infer_cameras_w2c', |
| 49 | '_partial_': True, |
| 50 | }) |
| 51 | ) |
| 52 | infer_cameras_w2c = hydra.utils.instantiate(infer_func_cfg) |
| 53 | |
| 54 | model_logger = logging.getLogger(f"relpose-angle-{model_keyname}") |
| 55 | for idx_dataset, dataset_name in enumerate(all_eval_datasets, start=1): |
| 56 | # 1. look up dataset config from configs/data, decide the dataset name |
| 57 | if dataset_name not in all_data_info: |
| 58 | raise ValueError(f"Unknown dataset in global data information: {dataset_name}") |
| 59 | dataset_info = all_data_info[dataset_name] |
| 60 | dataset = hydra.utils.instantiate(dataset_info.cfg) |
| 61 | |
| 62 | # 2. ready to read, and look up sampled ids from sequence name |
| 63 | model.eval() |
| 64 | sample_config: DictConfig = dataset_info.sampling |
| 65 | model_logger.info(f"Sampling strategy: {sample_config.strategy}") |
| 66 | with open(dataset_info.seq_id_map, "r") as f: |
| 67 | seq_id_map = json.load(f) |
| 68 | |
| 69 | # 3. prepare for metrics |
| 70 | rError = [] |
| 71 | tError = [] |
| 72 | metric_dict: dict = {} |
| 73 | model_logger.info(f"Evaluating {dataset_name} with {model_keyname}...") |
| 74 | tbar = tqdm(dataset.sequence_list, desc=f"[{dataset_name} eval]") |
| 75 | for seq_name in tbar: |
| 76 | # 4. decide sampling strategy to choose sample frames, from all frames (seq_num_frames) of a sequence |
| 77 | ids = seq_id_map[seq_name] |
| 78 | |
| 79 | # 5. load data sample (only extrinsics are used) |
no test coverage detected