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

Function main

eval_code/recons/videodepth/infer.py:18–106  ·  view source on GitHub ↗
(hydra_cfg: DictConfig)

Source from the content-addressed store, hash-verified

16
17@hydra.main(version_base="1.2", config_path="../configs", config_name="eval")
18def main(hydra_cfg: DictConfig):
19 # setup_debug(hydra_cfg.debug)
20 logger = logging.getLogger("videodepth-infer")
21
22 all_eval_models: ListConfig = hydra_cfg.eval_models # see configs/evaluation/videodepth.yaml
23 all_eval_datasets: ListConfig = hydra_cfg.eval_datasets # see configs/evaluation/videodepth.yaml
24 all_data_info: DictConfig = hydra_cfg.data # see configs/data
25 all_model_info: DictConfig = hydra_cfg.model # see configs/model
26
27 for idx_model, model_keyname in enumerate(all_eval_models, start=1):
28 # 0.1 look up model config from configs/model
29 if model_keyname not in all_model_info:
30 raise ValueError(f"Unknown model in global data information: {model_keyname}")
31 model_info = all_model_info[model_keyname]
32
33 # 0.2 load the model
34 model = hydra.utils.instantiate(model_info.cfg).to(hydra_cfg.device)
35 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 '???'}")
36
37 # 0.3 look up infer_videodepth function
38 infer_func_cfg = model_info.get(
39 "infer_videodepth",
40 DictConfig({
41 '_target_': f'interfaces.{model_keyname}.infer_videodepth',
42 '_partial_': True,
43 })
44 )
45 infer_videodepth = hydra.utils.instantiate(infer_func_cfg)
46
47 model_logger = logging.getLogger(f"videodepth-infer-{model_keyname}")
48 for idx_dataset, dataset_name in enumerate(all_eval_datasets, start=1):
49 # 1. look up dataset config from configs/data
50 if dataset_name not in all_data_info:
51 raise ValueError(f"Unknown dataset in global data information: {dataset_name}")
52 dataset_info = all_data_info[dataset_name]
53
54 # 2. get the sequence list
55 if dataset_info.type == "video":
56 # most of the datasets have many sequences of video
57 seq_list = get_all_sequences(dataset_info)
58 elif dataset_info.type == "mono":
59 raise ValueError("dataset type `mono` is not supported for videodepth evaluation")
60 else:
61 raise ValueError(f"Unknown dataset type: {dataset_info.type}")
62
63 model = model.eval()
64 output_root = osp.join(hydra_cfg.output_dir, model_keyname, dataset_name)
65 model_logger.info(f"[{idx_dataset}/{len(all_eval_datasets)}] Infering videodepth on {dataset_name} dataset..., output to {osp.relpath(output_root, hydra_cfg.work_dir)}")
66
67 # 3. infer for each sequence (video)
68 for seq_idx, seq in enumerate(seq_list, start=1):
69 filelist = list_imgs_a_sequence(dataset_info, seq)
70 save_dir = osp.join(output_root, seq)
71
72 if not hydra_cfg.overwrite and (osp.isdir(save_dir) and len(os.listdir(save_dir)) == 2 * len(filelist) + 1):
73 model_logger.info(f"[{seq_idx}/{len(seq_list)}] Sequence {seq} already processed, skipping.")
74 continue
75

Callers 1

infer.pyFile · 0.70

Calls 6

get_all_sequencesFunction · 0.90
list_imgs_a_sequenceFunction · 0.90
save_depth_mapsFunction · 0.90
getMethod · 0.80
infer_videodepthFunction · 0.50
joinMethod · 0.45

Tested by

no test coverage detected