def __getitem__(self, index): if self.is_test: img1 = frame_utils.read_gen(self.image_list[index][0]) img2 = frame_utils.read_gen(self.image_list[index][1]) img1 = np.array(img1).astype(np.uint8)[..., :3] img2 = np.array(img2).astype(np.uint8)[..., :3] img1 = torch.from_numpy(img1).permute(2, 0, 1).float() img2 = torch.from_numpy(img2).permute(2, 0, 1).float() return img1, img2, self.extra_info[index] if not self.init_seed: worker_info = torch.utils.data.get_worker_info() if worker_info is not None: torch.manual_seed(worker_info.id) np.random.seed(worker_info.id) random.seed(worker_info.id) self.init_seed = True index = index % len(self.image_list) valid = None if self.sparse: flow, valid = frame_utils.readFlowKITTI(self.flow_list[index]) else: flow = frame_utils.read_gen(self.flow_list[index]) img1 = frame_utils.read_gen(self.image_list[index][0]) img2 = frame_utils.read_gen(self.image_list[index][1]) flow = np.array(flow).astype(np.float32) img1 = np.array(img1).astype(np.uint8) img2 = np.array(img2).astype(np.uint8) # grayscale images if len(img1.shape) == 2: img1 = np.tile(img1[..., None], (1, 1, 3)) img2 = np.tile(img2[..., None], (1, 1, 3)) else: img1 = img1[..., :3] img2 = img2[..., :3] if self.augmentor is not None: if self.sparse: img1, img2, flow, valid = self.augmentor( img1, img2, flow, valid) else: img1, img2, flow = self.augmentor(img1, img2, flow) img1 = torch.from_numpy(img1).permute(2, 0, 1).float() img2 = torch.from_numpy(img2).permute(2, 0, 1).float() flow = torch.from_numpy(flow).permute(2, 0, 1).float() if valid is not None: valid = torch.from_numpy(valid) else: valid = (flow[0].abs() < 1000) & (flow[1].abs() < 1000) return img1, img2, flow, valid.float()
def __getitem__(self, index): np.random.seed() index = index % len(self.image_list) frame_id = self.image_list[index][0] frame_id = frame_id.split('/')[-1] img1 = frame_utils.read_gen(self.image_list[index][0]) img2 = frame_utils.read_gen(self.image_list[index][1]) flow, valid = frame_utils.readFlowKITTI(self.flow_list[index]) img1 = np.array(img1).astype(np.uint8)[..., :3] img2 = np.array(img2).astype(np.uint8)[..., :3] if self.do_augument: img1, img2, flow, valid = self.augumentor(img1, img2, flow, valid) img1 = torch.from_numpy(img1).permute(2, 0, 1).float() img2 = torch.from_numpy(img2).permute(2, 0, 1).float() flow = torch.from_numpy(flow).permute(2, 0, 1).float() valid = torch.from_numpy(valid).float() if self.do_pad: ht, wd = img1.shape[1:] pad_ht = (((ht // 128) + 1) * 128 - ht) % 128 pad_wd = (((wd // 128) + 1) * 128 - wd) % 128 pad_ht1 = [0, pad_ht] pad_wd1 = [pad_wd // 2, pad_wd - pad_wd // 2] pad = pad_wd1 + pad_ht1 img1 = img1.view(1, 3, ht, wd) img2 = img2.view(1, 3, ht, wd) flow = flow.view(1, 2, ht, wd) valid = valid.view(1, 1, ht, wd) img1 = torch.nn.functional.pad(img1, pad, mode='replicate') img2 = torch.nn.functional.pad(img2, pad, mode='replicate') flow = torch.nn.functional.pad(flow, pad, mode='constant', value=0) valid = torch.nn.functional.pad(valid, pad, mode='replicate', value=0) img1 = img1.view(3, ht + pad_ht, wd + pad_wd) img2 = img2.view(3, ht + pad_ht, wd + pad_wd) flow = flow.view(2, ht + pad_ht, wd + pad_wd) valid = valid.view(ht + pad_ht, wd + pad_wd) img1 = (img1 / 255 - 0.5) / 0.5 img2 = (img2 / 255 - 0.5) / 0.5 if self.return_path: return [img1, img2], flow, valid, frame_id return [img1, img2], flow, valid
def __getitem__(self, index): if self.is_test: img1 = frame_utils.read_gen(self.image_list[index][0]) img2 = frame_utils.read_gen(self.image_list[index][1]) img1 = np.array(img1).astype(np.uint8)[..., :3] img2 = np.array(img2).astype(np.uint8)[..., :3] img1 = torch.from_numpy(img1).permute(2, 0, 1).float() img2 = torch.from_numpy(img2).permute(2, 0, 1).float() return img1, img2, self.extra_info[index] if not self.init_seed: worker_info = torch.utils.data.get_worker_info() if worker_info is not None: torch.manual_seed(worker_info.id) np.random.seed(worker_info.id) random.seed(worker_info.id) self.init_seed = True index = index % len(self.image_list) valid = None if self.sparse: flow, valid = frame_utils.readFlowKITTI(self.flow_list[index]) else: flow = frame_utils.read_gen(self.flow_list[index]) img1 = frame_utils.read_gen(self.image_list[index][0]) img2 = frame_utils.read_gen(self.image_list[index][1]) flow = np.array(flow).astype(np.float32) img1 = np.array(img1).astype(np.uint8) img2 = np.array(img2).astype(np.uint8) # grayscale images if len(img1.shape) == 2: img1 = np.tile(img1[..., None], (1, 1, 3)) img2 = np.tile(img2[..., None], (1, 1, 3)) else: img1 = img1[..., :3] img2 = img2[..., :3] if self.augmentor is not None: if self.sparse: img1, img2, flow, valid = self.augmentor( img1, img2, flow, valid) else: img1, img2, flow = self.augmentor(img1, img2, flow) # cv2.imshow(f'img1{index}', cv2.cvtColor(img1, cv2.COLOR_RGB2BGR)) # cv2.imshow(f'img2{index}', cv2.cvtColor(img2, cv2.COLOR_RGB2BGR)) # cv2.imshow(f'flow{index}', cv2.cvtColor(flow_viz.flow_to_image(flow), cv2.COLOR_RGB2BGR)) # cv2.imshow(f'flowx{index}', flow[:, :, 0] / flow.max()) # cv2.imshow(f'flowy{index}', flow[:, :, 1] / flow.max()) img1 = torch.from_numpy(img1).permute(2, 0, 1).float() img2 = torch.from_numpy(img2).permute(2, 0, 1).float() flow = torch.from_numpy(flow).permute(2, 0, 1).float() if valid is not None: valid = torch.from_numpy(valid) else: valid = (flow[0].abs() < 1000) & (flow[1].abs() < 1000) # cv2.imshow(f'valid{index}', valid.float().numpy()) # cv2.waitKey(0) return img1, img2, flow, valid.float()
def __getitem__(self, index): if self.is_test: frame_id = self.image_list[index][0] frame_id = frame_id.split('/')[-1] img1 = frame_utils.read_gen(self.image_list[index][0]) img2 = frame_utils.read_gen(self.image_list[index][1]) img1 = np.array(img1).astype(np.uint8)[..., :3] img2 = np.array(img2).astype(np.uint8)[..., :3] img1 = torch.from_numpy(img1).permute(2, 0, 1).float() img2 = torch.from_numpy(img2).permute(2, 0, 1).float() return img1, img2, frame_id else: if not self.init_seed: worker_info = torch.utils.data.get_worker_info() if worker_info is not None: np.random.seed(worker_info.id) random.seed(worker_info.id) self.init_seed = True index = index % len(self.image_list) frame_id = self.image_list[index][0] frame_id = frame_id.split('/')[-1] img1 = frame_utils.read_gen(self.image_list[index][0]) img2 = frame_utils.read_gen(self.image_list[index][1]) flow, valid = frame_utils.readFlowKITTI(self.flow_list[index]) img1 = np.array(img1).astype(np.uint8)[..., :3] img2 = np.array(img2).astype(np.uint8)[..., :3] if self.do_augument: img1, img2, flow, valid = self.augumentor( img1, img2, flow, valid) img1 = torch.from_numpy(img1).permute(2, 0, 1).float() img2 = torch.from_numpy(img2).permute(2, 0, 1).float() flow = torch.from_numpy(flow).permute(2, 0, 1).float() valid = torch.from_numpy(valid).float() if self.do_pad: ht, wd = img1.shape[1:] pad_ht = (((ht // 8) + 1) * 8 - ht) % 8 pad_wd = (((wd // 8) + 1) * 8 - wd) % 8 pad_ht1 = [0, pad_ht] pad_wd1 = [pad_wd // 2, pad_wd - pad_wd // 2] pad = pad_wd1 + pad_ht1 img1 = img1.view(1, 3, ht, wd) img2 = img2.view(1, 3, ht, wd) flow = flow.view(1, 2, ht, wd) valid = valid.view(1, 1, ht, wd) img1 = torch.nn.functional.pad(img1, pad, mode='replicate') img2 = torch.nn.functional.pad(img2, pad, mode='replicate') flow = torch.nn.functional.pad(flow, pad, mode='constant', value=0) valid = torch.nn.functional.pad(valid, pad, mode='replicate', value=0) img1 = img1.view(3, ht + pad_ht, wd + pad_wd) img2 = img2.view(3, ht + pad_ht, wd + pad_wd) flow = flow.view(2, ht + pad_ht, wd + pad_wd) valid = valid.view(ht + pad_ht, wd + pad_wd) if self.is_test: return img1, img2, flow, valid, frame_id return img1, img2, flow, valid