Dequantizes a video tensor using per-channel metadata.
(video: torch.Tensor, meta: Dict[str, Any])
| 35 | return video, mins, maxs, original_shape |
| 36 | |
| 37 | def _dequantize_tensor(video: torch.Tensor, meta: Dict[str, Any]) -> torch.Tensor: |
| 38 | """Dequantizes a video tensor using per-channel metadata.""" |
| 39 | # Restore the min and max for each channel |
| 40 | mins = torch.tensor(meta["mins"], device=video.device).view(*([1] * (video.ndim - 1)), -1) |
| 41 | maxs = torch.tensor(meta["maxs"], device=video.device).view(*([1] * (video.ndim - 1)), -1) |
| 42 | |
| 43 | bit_depth = meta.get("bit_depth", 8) |
| 44 | max_val = (2**bit_depth) - 1 |
| 45 | |
| 46 | params_norm = video.to(torch.float32) / max_val |
| 47 | params = params_norm * (maxs - mins) + mins |
| 48 | |
| 49 | params = params.reshape(meta["shape"]) |
| 50 | dtype_str = str(meta["dtype"]) |
| 51 | if 'torch.' not in dtype_str: |
| 52 | dtype_str = f'torch.{dtype_str}' |
| 53 | |
| 54 | params = params.to(dtype=eval(dtype_str)) |
| 55 | return params |
| 56 | |
| 57 | def _save_metadata(meta: Dict[str, Any], metadata_path: str): |
| 58 | with open(metadata_path, "w") as f: |
no test coverage detected