(hydra_cfg: DictConfig)
| 19 | |
| 20 | @hydra.main(version_base="1.2", config_path="../configs", config_name="eval") |
| 21 | def main(hydra_cfg: DictConfig): |
| 22 | if not torch.cuda.is_available() or hydra_cfg.device != "cuda": |
| 23 | raise EnvironmentError("Sampling with DDP requires at least one GPU. sample.py supports CPU-only usage") |
| 24 | dist.init_process_group("nccl") |
| 25 | rank = dist.get_rank() |
| 26 | device = rank % torch.cuda.device_count() |
| 27 | |
| 28 | torch.cuda.set_device(device) |
| 29 | print(f"Starting rank={rank}, world_size={dist.get_world_size()}.") |
| 30 | |
| 31 | all_eval_models: DictConfig = hydra_cfg.eval_models # see configs/evaluation/relpose-distance.yaml |
| 32 | all_eval_datasets: DictConfig = hydra_cfg.eval_datasets # see configs/evaluation/relpose-distance.yaml |
| 33 | all_data_info: DictConfig = hydra_cfg.data # see configs/data |
| 34 | all_model_info: DictConfig = hydra_cfg.model # see configs/model |
| 35 | |
| 36 | for idx_model, model_keyname in enumerate(all_eval_models, start=1): |
| 37 | # 0.1 look up model config from configs/model, decide the model name (to save) |
| 38 | if model_keyname not in all_model_info: |
| 39 | raise ValueError(f"Unknown model in global data information: {model_keyname}") |
| 40 | model_info = all_model_info[model_keyname] |
| 41 | |
| 42 | # 0.2 load the model |
| 43 | model = hydra.utils.instantiate(model_info.cfg).to(hydra_cfg.device) |
| 44 | model_logger = logging.getLogger(f"relpose-dist-{model_keyname}-rank{rank}") |
| 45 | model_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 '???'}") |
| 46 | |
| 47 | # 0.3 route the correct infer function for the model |
| 48 | infer_func_cfg = model_info.get( |
| 49 | "infer_cameras_c2w", |
| 50 | DictConfig({ |
| 51 | '_target_': f'interfaces.{model_keyname}.infer_cameras_c2w', |
| 52 | '_partial_': True, |
| 53 | }) |
| 54 | ) |
| 55 | infer_cameras_c2w = hydra.utils.instantiate(infer_func_cfg) |
| 56 | |
| 57 | all_seq_list = [] |
| 58 | output_root = osp.join(hydra_cfg.output_dir, model_keyname) |
| 59 | for dataset_name in all_eval_datasets: |
| 60 | # 1. look up dataset config from configs/data, decide the dataset name |
| 61 | if dataset_name not in all_data_info: |
| 62 | raise ValueError(f"Unknown dataset: {dataset_name}") |
| 63 | dataset_info = all_data_info[dataset_name] |
| 64 | |
| 65 | # 2. get the sequence list |
| 66 | seq_list = get_all_sequences(dataset_info) |
| 67 | all_seq_list.extend([(dataset_name, seq) for seq in seq_list]) |
| 68 | |
| 69 | save_dir = osp.join(output_root, dataset_name) |
| 70 | if rank == 0: |
| 71 | make_csvsdir_and_remove_history_csvs( |
| 72 | input_root=osp.join(save_dir, "_seq_metrics"), |
| 73 | seqs_csv_file=osp.join(save_dir, "_seq_metrics.csv") |
| 74 | ) |
| 75 | |
| 76 | # 3. infer for each sequence |
| 77 | model = model.eval() |
| 78 | model_logger.info(f"Start infering relpose(c2w) on dataset..., output to {osp.relpath(output_root, hydra_cfg.work_dir)}") |
no test coverage detected