Download core/base_method.py from KCBtheone/SplatAtlas: direct link, hf CLI and curl.
- Browser
- Download file 2.85 kB
-
https://huggingface.co/KCBtheone/SplatAtlas/resolve/main/core/base_method.py
- Command line
-
hf download hf://KCBtheone/SplatAtlas/core/base_method.py
-
curl -L -o base_method.py https://huggingface.co/KCBtheone/SplatAtlas/resolve/main/core/base_method.py
2.85 kB
| import abc | |
| from typing import Dict, Any, List | |
| import torch | |
| class BaseMethod(abc.ABC): | |
| """ | |
| SplatAtlas 的统一抽象基类。 | |
| 所有 3DGS 变体必须继承此接口,强制隔离内部逻辑与外部评测管线。 | |
| """ | |
| def __init__(self, dataset_config: Dict, hyperparams: Dict): | |
| """初始化模型、优化器等,不启动训练""" | |
| pass | |
| def train_iteration(self, step: int) -> Dict[str, float]: | |
| """ | |
| 执行单步前向与反向传播,包含致密化逻辑。 | |
| 必须返回包含指标的字典,如: | |
| {"loss": loss, "num_gaussians": N, "pos_grad_norm": grad, "gamma_median": gamma} | |
| """ | |
| pass | |
| def render(self, camera: Any) -> Dict[str, torch.Tensor]: | |
| """无梯度渲染图像,返回 {"image": tensor, "depth": tensor(可选)}""" | |
| pass | |
| def save(self, save_dir: str, step: int): | |
| """将 .ply 和 checkpoints 落盘""" | |
| pass | |
| def load(self, model_path: str, iteration: int): | |
| """ | |
| 强制实现:负责正确加载 .ply, MLP权重, 哈希表等所有必要资产。 | |
| 绝对禁止外部脚本绕过此方法直接读取 .ply 文件。 | |
| """ | |
| pass | |
| def get_spatial_centers(self) -> torch.Tensor: | |
| """ | |
| 核心约束:返回 [N, 3] 的拓扑中心坐标张量。 | |
| 用于流形坍塌检测(Manifold Collapse)以及与 COLMAP SfM 点云的绝对宇宙坐标系对齐(ICP)。 | |
| 若是隐式表面/哈希网格,须返回表面等值面的采样点。 | |
| """ | |
| raise NotImplementedError("该 Wrapper 尚未实现 get_spatial_centers") | |
| def compute_physical_metrics(self, cameras: List[Any] = None) -> Dict[str, float]: | |
| """ | |
| 由变体自身决定如何计算表征特异性指标(如畸变度、SH能量)。 | |
| 引入 cameras 以支持视图依赖型(View-Dependent)指标的计算。 | |
| 若尚未实现,可抛出 NotImplementedError。 | |
| """ | |
| raise NotImplementedError("该 Wrapper 尚未实现 compute_physical_metrics") | |
| def evaluate_spatial_field(self, query_points: torch.Tensor, cameras: List[Any] = None) -> torch.Tensor: | |
| """ | |
| 核心重构:评估表征在指定 3D 坐标网格上的标量场(密度/不透明度/占用率)。 | |
| - query_points: [V, 3] 的查询网格坐标张量。 | |
| - cameras: 观察这些点的相机列表(用于打破视图依赖死锁)。 | |
| - 返回: [V] 的标量张量,表示每个点的空间物理量。 | |
| """ | |
| raise NotImplementedError("该 Wrapper 尚未实现 evaluate_spatial_field") | |