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

Method __init__

eval_code/recons/datasets/sevenscenes.py:22–87  ·  view source on GitHub ↗
(
        self,
        SEVENSCENES_DIR: str,
        split: str = 'test',
        load_img_size: int = 518,
        cache_file: str = "data/dataset_cache/7scenes_mv_recon_cache.npy",
    )

Source from the content-addressed store, hash-verified

20
21class SevenScenes(Dataset):
22 def __init__(
23 self,
24 SEVENSCENES_DIR: str,
25 split: str = 'test',
26 load_img_size: int = 518,
27 cache_file: str = "data/dataset_cache/7scenes_mv_recon_cache.npy",
28 ):
29
30 self.SEVENSCENES_DIR = SEVENSCENES_DIR
31 if SEVENSCENES_DIR == None:
32 raise NotImplementedError
33 print(f"SEVENSCENES_DIR is {SEVENSCENES_DIR}")
34
35 self.split = split
36 if self.split in ['train', 'test']:
37 split_txt_name = f"{self.split.capitalize()}Split.txt"
38 else:
39 raise ValueError(f"Invalid split: {self.split}. Must be 'train' or 'test'.")
40
41 if osp.exists(cache_file):
42 print(f"[7Scenes] Loading from cache file: {cache_file}")
43 self.metadata = np.load(cache_file, allow_pickle=True).item()
44 self.sequence_list = sorted(list(self.metadata.keys()))
45 else:
46 print(f"[7Scenes] Cache file not found, loading from {SEVENSCENES_DIR}")
47
48 scene_list = sorted(
49 [d for d in os.listdir(SEVENSCENES_DIR) if osp.isdir(osp.join(SEVENSCENES_DIR, d))]
50 )
51
52 self.sequence_list = []
53 for scene in scene_list:
54 scene_dir = osp.join(SEVENSCENES_DIR, scene)
55 split_txt_file = osp.join(scene_dir, split_txt_name)
56 # from "sequenceX" to "scene/seq-0X"
57 seq_name_trans = lambda rawname: f"{scene}/seq-{int(rawname[len('sequence'):]):02d}"
58 with open(split_txt_file, 'r') as f:
59 scene_seq_list = [seq_name_trans(line.strip()) for line in f.readlines()]
60 self.sequence_list.extend(scene_seq_list)
61
62 self.metadata = {}
63 for seq in tqdm(self.sequence_list):
64 seq_path = osp.join(SEVENSCENES_DIR, seq)
65
66 list_seqs_func = lambda suffix: sorted(
67 [d for d in os.listdir(seq_path) if d.endswith(suffix)]
68 )
69 seq_rgbs = list_seqs_func('.color.png')
70 seq_depths = list_seqs_func('.depth.proj.png')
71 seq_poses = list_seqs_func('.pose.txt')
72
73 if not (len(seq_rgbs) == len(seq_depths) == len(seq_poses)):
74 raise ValueError(f"Sequence {seq} has mismatched number of RGB, depth, and pose files: {len(seq_rgbs)}, {len(seq_depths)}, {len(seq_poses)}")
75 get_number_func = lambda x: int(x.split('-')[1].split('.')[0])
76 if not (get_number_func(seq_rgbs[0]) == get_number_func(seq_depths[0]) == get_number_func(seq_poses[0]) == 0):
77 raise ValueError(f"First frame of sequence {seq} has number of RGB, depth, and pose != 0: {seq_rgbs[0]}, {seq_depths[0]}, {seq_poses[0]}")
78 if not (get_number_func(seq_rgbs[-1]) == get_number_func(seq_depths[-1]) == get_number_func(seq_poses[-1]) == len(seq_rgbs) - 1):
79 raise ValueError(f"Last frame of sequence {seq} has number of RGB, depth, and pose != N-1: {seq_rgbs[-1]}, {seq_depths[-1]}, {seq_poses[-1]}, N={len(seq_rgbs)}")

Callers

nothing calls this directly

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected