MCPcopy Create free account
hub / github.com/DSL-Lab/StreamSplat / __getitem__

Method __getitem__

datasets/provider_vos.py:100–185  ·  view source on GitHub ↗
(self, index)

Source from the content-addressed store, hash-verified

98 return len(self.ret_frames)
99
100 def __getitem__(self, index):
101 set_idx, image_path, timestamp, frame_idx = self.ret_frames[index]
102
103 if not osp.exists(image_path):
104 raise FileNotFoundError(f"Image not found: {image_path}")
105
106 main_image = Image.open(image_path).convert("RGB")
107 depth_path = self.get_predicted_depth_path(image_path)
108 depth_image = Image.open(depth_path)
109 main_image = self.transform(main_image)
110 depth_image = self.depth_transform(depth_image)
111
112 if self.training:
113 mask_path = image_path.replace(self.images_root, self.mask_root).replace(".jpg", ".png")
114 if not osp.exists(mask_path):
115 raise FileNotFoundError(f"Mask not found: {mask_path}")
116 mask_image = Image.open(mask_path)
117 mask_image = self.transform_mask(mask_image).unsqueeze(0)
118 else:
119 mask_image = torch.ones_like(depth_image)
120
121 frames = [main_image]
122 depths = [depth_image]
123 masks = [mask_image]
124 timestamps_list = [0.0]
125
126 seq_length = self.set_len[set_idx]
127 current_idx = frame_idx
128
129 if self.opt.output_frames > 1 and seq_length > 1:
130 if not self.shuffle:
131 # pick frame with fixed interval
132 if current_idx + self.nearby_range >= seq_length:
133 interval = (seq_length - current_idx) // (self.opt.output_frames - 1)
134 else:
135 interval = self.nearby_range // (self.opt.output_frames - 1)
136 assert interval > 0, "Interval must be greater than 0"
137 offsets = [i * interval for i in range(1, self.opt.output_frames)]
138 else:
139 if current_idx + self.nearby_range >= seq_length:
140 offsets = random.sample(range(1, seq_length - current_idx), self.opt.output_frames - 1)
141 else:
142 offsets = random.sample(range(1, self.nearby_range + 1), self.opt.output_frames - 1)
143
144 offsets.sort()
145
146 for offset in offsets:
147 pair_idx = current_idx + offset
148 img_file_pair, ts_pair = self.frame_infos[set_idx][pair_idx]
149 if not osp.exists(img_file_pair):
150 print(f"Warning: Missing file {img_file_pair}")
151 continue
152 pair_image = Image.open(img_file_pair).convert("RGB")
153 pair_depth_path = self.get_predicted_depth_path(img_file_pair)
154 pair_depth_image = Image.open(pair_depth_path)
155 pair_image = self.transform(pair_image)
156 pair_depth_image = self.depth_transform(pair_depth_image)
157

Callers

nothing calls this directly

Calls 3

transform_maskMethod · 0.95
sampleMethod · 0.80

Tested by

no test coverage detected