| 205 | return len(self.images_list) |
| 206 | |
| 207 | class ValidateData(data.Dataset): |
| 208 | def __init__(self, args, split): |
| 209 | self.root = os.path.join(args.validate_data_dir, split) |
| 210 | if not os.path.exists(self.root): |
| 211 | raise colored('[Error: ]', 'red') + 'file path {:s} is not exist!'.format(self.root) |
| 212 | |
| 213 | self.images_dir = os.path.join(self.root, 'images') |
| 214 | self.flows_dir = os.path.join(self.root, 'flows') |
| 215 | self.masks_dir = os.path.join(self.root, 'masks') |
| 216 | |
| 217 | |
| 218 | def __getitem__(self, index): |
| 219 | im1 = cv2.imread(os.path.join(self.images_dir, 'image_{:06d}_0.png'.format(index))) |
| 220 | im2 = cv2.imread(os.path.join(self.images_dir, 'image_{:06d}_1.png'.format(index))) |
| 221 | flow = readFlow(os.path.join(self.flows_dir, 'flow_{:06d}.flo'.format(index))) |
| 222 | |
| 223 | H, W = im1.shape[:2] |
| 224 | |
| 225 | im1 = torch.from_numpy(im1).permute([2, 0, 1]) |
| 226 | im2 = torch.from_numpy(im2).permute([2, 0, 1]) |
| 227 | flow = torch.from_numpy(flow).permute([2, 0, 1]) |
| 228 | |
| 229 | valid_mask = np.ones([H, W]).astype(bool) |
| 230 | if os.path.exists(self.masks_dir): |
| 231 | valid_mask = cv2.imread(os.path.join(self.masks_dir, 'mask_{:06d}.png'.format(index)), cv2.IMREAD_UNCHANGED).astype(bool) |
| 232 | return im1, im2, flow, valid_mask |
| 233 | |
| 234 | def __len__(self): |
| 235 | return len(os.listdir(self.flows_dir)) |
| 236 | |
| 237 | def fetch_dataloader(args, split='train'): |
| 238 | print(colored('[Data]: ', 'yellow') + 'Loading MegaDepth CAPS') |
no outgoing calls
no test coverage detected