MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / main

Function main

eval_code/recons/relpose/eval_dist.py:22–164  ·  view source on GitHub ↗
(hydra_cfg: DictConfig)

Source from the content-addressed store, hash-verified

20
21@hydra.main(version_base="1.2", config_path="../configs", config_name="eval")
22def main(hydra_cfg: DictConfig):
23 # setup_debug(hydra_cfg.debug)
24 logger = logging.getLogger("relpose-dist")
25
26 all_eval_models: DictConfig = hydra_cfg.eval_models # see configs/evaluation/relpose-distance.yaml
27 all_eval_datasets: DictConfig = hydra_cfg.eval_datasets # see configs/evaluation/relpose-distance.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 for idx_model, model_keyname in enumerate(all_eval_models, start=1):
32 # 0.1 look up model config from configs/model, decide the model name (to save)
33 if model_keyname not in all_model_info:
34 raise ValueError(f"Unknown model in global data information: {model_keyname}")
35 model_info = all_model_info[model_keyname]
36
37 # 0.2 load the model
38 model = hydra.utils.instantiate(model_info.cfg).to(hydra_cfg.device)
39 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 '???'}")
40
41 # 0.3 route the correct infer function for the model
42 infer_func_cfg = model_info.get(
43 "infer_cameras_c2w",
44 DictConfig({
45 '_target_': f'interfaces.{model_keyname}.infer_cameras_c2w',
46 '_partial_': True,
47 })
48 )
49 infer_cameras_c2w = hydra.utils.instantiate(infer_func_cfg)
50
51 model_logger = logging.getLogger(f"relpose-dist-{model_keyname}")
52 for idx_dataset, dataset_name in enumerate(all_eval_datasets, start=1):
53 # 1. look up dataset config from configs/data, decide the dataset name
54 if dataset_name not in all_data_info:
55 raise ValueError(f"Unknown dataset: {dataset_name}")
56 dataset_info = all_data_info[dataset_name]
57
58 # 2. get the sequence list
59 seq_list = get_all_sequences(dataset_info)
60 output_root = osp.join(hydra_cfg.output_dir, model_keyname, dataset_name)
61 os.makedirs(output_root, exist_ok=True)
62
63 # 3. infer for each sequence
64 model = model.eval()
65 model_logger.info(f"[{idx_dataset}/{len(all_eval_datasets)}] Infering relpose(c2w) on {dataset_name} dataset..., output to {osp.relpath(output_root, hydra_cfg.work_dir)}")
66
67 results = []
68 tbar = tqdm(seq_list, desc=f"[{dataset_name} eval]")
69 for seq in tbar:
70 try:
71 # 4.1 list all images of this sequence
72 filelist = list_imgs_a_sequence(dataset_info, seq)
73 filelist = filelist[:: hydra_cfg.pose_eval_stride]
74
75 # 4.2 real inference
76 # pr_poses: c2w poses, (N, 3, 4), in torch
77 # pr_intrs: focals + pps, (N, 3, 3), in numpy
78 pr_poses, pr_intrs = infer_cameras_c2w(filelist, model, hydra_cfg)
79 pred_traj = get_tum_poses(pr_poses)

Callers 1

eval_dist.pyFile · 0.70

Calls 13

get_all_sequencesFunction · 0.90
list_imgs_a_sequenceFunction · 0.90
get_tum_posesFunction · 0.90
save_tum_posesFunction · 0.90
save_list_of_matricesFunction · 0.90
load_trajFunction · 0.90
eval_metricsFunction · 0.90
plot_trajectoryFunction · 0.90
write_csvFunction · 0.90
calculate_averagesFunction · 0.90
getMethod · 0.80
infer_cameras_c2wFunction · 0.50

Tested by

no test coverage detected