(hydra_cfg: DictConfig)
| 21 | |
| 22 | @hydra.main(version_base="1.2", config_path="../configs", config_name="eval") |
| 23 | def main(hydra_cfg: DictConfig): |
| 24 | # setup_debug(hydra_cfg.debug) |
| 25 | |
| 26 | all_eval_models: DictConfig = hydra_cfg.eval_models # see configs/evaluation/mv_recon.yaml |
| 27 | all_eval_datasets: DictConfig = hydra_cfg.eval_datasets # see configs/evaluation/mv_recon.yaml |
| 28 | all_data_info: DictConfig = hydra_cfg.data # see configs/data |
| 29 | all_model_info: DictConfig = hydra_cfg.model # see configs/model |
| 30 | |
| 31 | logger = logging.getLogger("mv_recon-eval") |
| 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 | infer_func_cfg = model_info.get( |
| 45 | "infer_mv_pointclouds", |
| 46 | DictConfig({ |
| 47 | '_target_': f'interfaces.{model_keyname}.infer_mv_pointclouds', |
| 48 | '_partial_': True, |
| 49 | }) |
| 50 | ) |
| 51 | infer_mv_pointclouds = hydra.utils.instantiate(infer_func_cfg) |
| 52 | |
| 53 | model_logger = logging.getLogger(f"mv_recon-eval-{model_keyname}") |
| 54 | for idx_dataset, dataset_name in enumerate(all_eval_datasets, start=1): |
| 55 | # 1.1 look up dataset config from configs/data, decide the dataset name, and load the dataset |
| 56 | if dataset_name not in all_data_info: |
| 57 | raise ValueError(f"Unknown dataset in global data information: {dataset_name}") |
| 58 | dataset_info = all_data_info[dataset_name] |
| 59 | dataset = hydra.utils.instantiate(dataset_info.cfg) |
| 60 | |
| 61 | # 1.2 ready for output directory & metrics |
| 62 | output_root = osp.join(hydra_cfg.output_dir, model_keyname, dataset_name) |
| 63 | os.makedirs(output_root, exist_ok=True) |
| 64 | all_data_dict = { |
| 65 | "model": model_keyname, |
| 66 | "Acc-mean": 0.0, "Acc-med": 0.0, |
| 67 | "Comp-mean": 0.0, "Comp-med": 0.0, |
| 68 | "NC-mean": 0.0, "NC-med": 0.0, |
| 69 | "NC1-mean": 0.0, "NC1-med": 0.0, |
| 70 | "NC2-mean": 0.0, "NC2-med": 0.0, |
| 71 | } |
| 72 | |
| 73 | # 1.3 load pre-sampled seq-id-map |
| 74 | model_logger.info(f"[{idx_dataset}/{len(all_eval_datasets)}] Evaluating Multi-View Pointcloud Reconstruction on dataset {dataset_name}...") |
| 75 | sample_config: DictConfig = dataset_info.sampling |
| 76 | model_logger.info(f"Sampling strategy: {sample_config.strategy}") |
| 77 | with open(dataset_info.seq_id_map, "r") as f: |
| 78 | seq_id_map: dict = json.load(f) |
| 79 | |
| 80 | model_logger.info(f"Evaluating {dataset_name} with {model_keyname}...") |
no test coverage detected