Load and validate motion tensor from a .pt file.
(path: Path)
| 49 | |
| 50 | |
| 51 | def load_motion_tensor(path: Path) -> torch.Tensor: |
| 52 | """Load and validate motion tensor from a .pt file.""" |
| 53 | data = torch.load(path, map_location="cpu") |
| 54 | if isinstance(data, dict): |
| 55 | if "motion" in data: |
| 56 | data = data["motion"] |
| 57 | else: |
| 58 | raise ValueError(f"{path} contains a dict but no 'motion' field.") |
| 59 | if not torch.is_tensor(data): |
| 60 | data = torch.as_tensor(data) |
| 61 | if data.ndim != 2: |
| 62 | raise ValueError(f"Expected a 2D motion tensor in {path}, got shape {tuple(data.shape)}") |
| 63 | return data.float() |
| 64 | |
| 65 | |
| 66 | def convert_motion_to_joints(motion_tensor: torch.Tensor) -> np.ndarray: |