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

Method __init__

eval_code/recons/datasets/nrgbd.py:23–90  ·  view source on GitHub ↗
(
        self,
        NRGBD_DIR: str,
        load_img_size: int = 518,
        cache_file: str = "data/dataset_cache/nrgbd_mv_recon_cache.npy",
    )

Source from the content-addressed store, hash-verified

21
22class NRGBD(Dataset):
23 def __init__(
24 self,
25 NRGBD_DIR: str,
26 load_img_size: int = 518,
27 cache_file: str = "data/dataset_cache/nrgbd_mv_recon_cache.npy",
28 ):
29
30 self.NRGBD_DIR = NRGBD_DIR
31 if NRGBD_DIR == None:
32 raise NotImplementedError
33 print(f"NRGBD_DIR is {NRGBD_DIR}")
34
35 if osp.exists(cache_file):
36 print(f"[NRGBD] Loading from cache file: {cache_file}")
37 self.metadata = np.load(cache_file, allow_pickle=True).item()
38 self.sequence_list = sorted(list(self.metadata.keys()))
39 else:
40 print(f"[NRGBD] Cache file not found, loading from {NRGBD_DIR}")
41
42 self.sequence_list = sorted(
43 [d for d in os.listdir(NRGBD_DIR) if osp.isdir(osp.join(NRGBD_DIR, d))]
44 )
45
46 self.metadata = {}
47 for seq in tqdm(self.sequence_list):
48 seq_path = osp.join(NRGBD_DIR, seq)
49
50 list_seqs_func = lambda subdir, prefix, suffix: sorted(
51 [d for d in os.listdir(osp.join(seq_path, subdir)) if d.endswith(suffix)],
52 key=lambda file: int(file.split('.')[0][len(prefix):])
53 )
54 seq_rgbs = list_seqs_func(subdir='images', prefix='img', suffix='.png')
55 seq_depths = list_seqs_func(subdir='depth', prefix='depth', suffix='.png')
56
57 seq_pose_file = osp.join(seq_path, 'poses.txt')
58 with open(seq_pose_file, 'r') as f:
59 seq_poses_rawlines = [line.strip() for line in f.readlines()]
60
61 seq_poses = []
62 lines_per_matrix = 4
63 for i in range(0, len(seq_poses_rawlines), lines_per_matrix):
64 pose_floats = [
65 [float(x) for x in line.split()]
66 for line in seq_poses_rawlines[i : i + lines_per_matrix]
67 ]
68 seq_poses.append(pose_floats)
69
70 # return np.array(seq_poses, dtype=np.float32)
71
72 if not (len(seq_rgbs) == len(seq_depths) == len(seq_poses)):
73 raise ValueError(f"Sequence {seq} has mismatched number of RGB, depth, and pose files: {len(seq_rgbs)}, {len(seq_depths)}, {len(seq_poses)}")
74
75 if not (int(seq_rgbs[0].split('.')[0][len('img'):]) == int(seq_depths[0].split('.')[0][len('depth'):]) == 0):
76 raise ValueError(f"First frame of sequence {seq} has number of RGB and depth != 0: {seq_rgbs[0]}, {seq_depths[0]}, {seq_poses[0]}")
77 if not (int(seq_rgbs[-1].split('.')[0][len('img'):]) == int(seq_depths[-1].split('.')[0][len('depth'):]) == len(seq_rgbs) - 1):
78 raise ValueError(f"Last frame of sequence {seq} has number of RGB and depth != N-1: {seq_rgbs[-1]}, {seq_depths[-1]}, N={len(seq_rgbs)}")
79
80 # camera_pose[:, 1:3] *= -1.0

Callers

nothing calls this directly

Calls 2

closed_form_inverse_se3Function · 0.90
joinMethod · 0.45

Tested by

no test coverage detected