| 16 | |
| 17 | |
| 18 | def preprocess_data(frames, depths, timestamps, device): |
| 19 | frames = torch.from_numpy(np.stack(frames)).float().to(device) / 255.0 # [V, H, W, C] -> [V, C, H, W] |
| 20 | frames = frames.permute(0, 3, 1, 2).unsqueeze(0) # [1, V, C, H, W] |
| 21 | |
| 22 | depths = torch.from_numpy(np.stack(depths)).float().to(device) # [V, H, W] |
| 23 | depths = depths.unsqueeze(1).unsqueeze(0) # [1, V, 1, H, W] |
| 24 | |
| 25 | timestamps = torch.tensor(timestamps, dtype=torch.float32, device=device).unsqueeze(0) # [1, V] |
| 26 | |
| 27 | timestamps = timestamps / (timestamps[..., -1].unsqueeze(-1)) |
| 28 | |
| 29 | max_depth = depths.flatten(1).max(dim=1)[0][:, None, None, None, None] |
| 30 | min_depth = depths.flatten(1).min(dim=1)[0][:, None, None, None, None] |
| 31 | input_depths = (depths - min_depth) / (max_depth - min_depth + 1e-8) |
| 32 | |
| 33 | return frames, input_depths, timestamps |
| 34 | |
| 35 | def get_image(path, H, W): |
| 36 | """Load and resize an image.""" |