MCPcopy Create free account
hub / github.com/JasonLSC/GSCodec_Studio / _dequantize_tensor

Function _dequantize_tensor

examples/gs_ply_process.py:37–55  ·  view source on GitHub ↗

Dequantizes a video tensor using per-channel metadata.

(video: torch.Tensor, meta: Dict[str, Any])

Source from the content-addressed store, hash-verified

35 return video, mins, maxs, original_shape
36
37def _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
57def _save_metadata(meta: Dict[str, Any], metadata_path: str):
58 with open(metadata_path, "w") as f:

Callers 1

postprocess_gs_plyFunction · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected