> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-zh/3d-sheng-cheng/gaussian-splatting.md).

# 3D 高斯泼溅

**3D 高斯泼溅** 是一种革命性的实时 3D 场景重建技术，拥有超过 **15,000 个 GitHub 星标**。不同于基于 NeRF 的方法，高斯泼溅将场景表示为数百万个微小的 3D 高斯体，可在 **实时帧率** （100+ FPS）下渲染，同时达到照片级真实质量。将其部署到 Clore.ai 的 GPU 云上，即可从你自己的照片重建并探索 3D 场景。

***

## 什么是 3D 高斯泼溅？

传统的 NeRF 方法将场景隐式编码在神经网络中，渲染时需要逐像素进行光线行进。高斯泼溅采取了一种根本不同的方法：

1. **初始化：** 从稀疏点云开始（来自 COLMAP）
2. **表示：** 将每个点扩展为一个具有位置、尺度、旋转、不透明度和球谐颜色的 3D 高斯体
3. **优化：** 对高斯体进行可微渲染，并与训练图像进行优化
4. **渲染：** 通过 alpha 合成将高斯体投影到图像平面上（极快）

**相对于 NeRF 的主要优势：**

* 实时渲染（1080p 下 100+ FPS）
* 更好的细节重建
* 显式 3D 表示（可编辑、可导出）
* 训练更快（30–60 分钟，而非数小时）
* 可在消费级 GPU 上运行

***

## 前提条件

| 要求     | 最低            | 推荐              |
| ------ | ------------- | --------------- |
| GPU 显存 | 12 GB         | 24 GB           |
| GPU    | RTX 3080 12GB | RTX 4090 / A100 |
| 内存     | 16 GB         | 32 GB           |
| 存储     | 30 GB         | 60 GB           |
| CUDA   | 12.8+         | 12.8+           |

{% hint style="warning" %}
高斯泼溅对 CUDA 有严格要求。CUDA 版本必须与 `diff-gaussian-rasterization` 已编译的扩展相匹配。使用提供的 Dockerfile 可消除兼容性问题。
{% endhint %}

***

## 步骤 1——在 Clore.ai 上租用 GPU

1. 登录到 [clore.ai](https://clore.ai).
2. 点击 **市场** 并按 VRAM ≥ 16 GB 进行筛选。
3. 选择一台服务器——RTX 4090 提供最佳性价比。
4. 将 Docker 镜像设置为你的自定义镜像（见步骤 2）。
5. 设置开放端口： `22` （SSH）和 `8080` （网页查看器）。
6. 点击 **租用**.

***

## 步骤 2 — Dockerfile

使用所有依赖项构建自定义 Docker 镜像：

```dockerfile
FROM pytorch/pytorch:2.11.0-cuda12.8-cudnn9-devel

ENV DEBIAN_FRONTEND=noninteractive
ENV TORCH_CUDA_ARCH_LIST="6.0;6.1;7.0;7.5;8.0;8.6;8.9;9.0+PTX"

RUN apt-get update && apt-get install -y \
    git wget curl cmake build-essential \\
    libboost-program-options-dev libboost-filesystem-dev \\
    libboost-graph-dev libboost-system-dev libboost-test-dev \\
    libeigen3-dev libflann-dev libfreeimage-dev \\
    libmetis-dev libgoogle-glog-dev libgflags-dev \\
    libsqlite3-dev libglew-dev qtbase5-dev libqt5opengl5-dev \\
    libcgal-dev libceres-dev \\
    ffmpeg libgl1 libglib2.0-0 \\
    openssh-server \
    python3-pip python3-dev \\
    && rm -rf /var/lib/apt/lists/*

# 安装 COLMAP
RUN apt-get update && apt-get install -y colmap && rm -rf /var/lib/apt/lists/*

# 配置 SSH
RUN mkdir /var/run/sshd && \
    echo 'root:clore123' | chpasswd && \
    sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

WORKDIR /workspace

# 克隆原始 3DGS 仓库
RUN git clone https://github.com/graphdeco-inria/gaussian-splatting /workspace/gaussian-splatting \\
    --recursive

# 安装 Python 依赖
RUN cd /workspace/gaussian-splatting && \\
    pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128 && \\
    pip install -r requirements.txt

# 构建 CUDA 扩展
RUN cd /workspace/gaussian-splatting && \\
    pip install submodules/diff-gaussian-rasterization && \\
    pip install submodules/simple-knn

# 安装网页查看器依赖项
RUN pip install viser==0.1.29 nerfview==0.0.4 trimesh

EXPOSE 22 8080

CMD service ssh start && tail -f /dev/null
```

### 构建并推送

构建镜像并将其推送到你自己的 Docker Hub 账户（替换 `YOUR_DOCKERHUB_USERNAME` 为你的实际用户名）：

```bash
docker build -t YOUR_DOCKERHUB_USERNAME/gaussian-splatting:latest .
docker push YOUR_DOCKERHUB_USERNAME/gaussian-splatting:latest
```

{% hint style="info" %}
Docker Hub 上没有官方预构建的 3D 高斯泼溅 Docker 镜像。位于 [graphdeco-inria/gaussian-splatting](https://github.com/graphdeco-inria/gaussian-splatting) 的官方仓库并未提供——请使用上面的 Dockerfile 自行构建。镜像必须使用与目标 GPU 匹配的正确 CUDA 架构标志进行构建。
{% endhint %}

使用 `YOUR_DOCKERHUB_USERNAME/gaussian-splatting:latest` 在你的 Clore.ai 配置中。

***

## 步骤 3 — 通过 SSH 连接

```bash
ssh root@<clore-host> -p <assigned-ssh-port>
```

验证构建：

```bash
cd /workspace/gaussian-splatting
python -c "from diff_gaussian_rasterization import GaussianRasterizationSettings; print('CUDA extension OK')"
```

***

## 步骤 4 — 准备你的数据集

### 选项 A：使用 Tandt（Tanks and Temples）数据集

用于快速测试的经典基准数据集：

```bash
mkdir -p /workspace/data && cd /workspace/data

# 下载小型测试场景
wget https://repo-sam.inria.fr/fungraph/3d-gaussian-splatting/datasets/input/tandt.zip
unzip tandt.zip
```

### 选项 B：处理你自己的照片

```bash
# 上传照片
scp -P <port> -r ./my_photos/ root@<clore-host>:/workspace/data/

# 运行 COLMAP 处理脚本（3DGS 随附）
cd /workspace/gaussian-splatting

python convert.py \\
    -s /workspace/data/my_photos \\
    --no_gpu   # 可选：如果 COLMAP GPU 求解器冲突
```

{% hint style="info" %}
该 `convert.py` 该脚本会运行完整的 COLMAP 流程：特征提取、匹配、稀疏重建和去畸变。根据图像数量不同，这需要 5–30 分钟。
{% endhint %}

### 选项 C：从视频处理

```bash
# 以 2fps 从视频中提取帧
ffmpeg -i /workspace/data/my_video.mp4 \\
    -vf fps=2 \\
    /workspace/data/frames/frame_%04d.jpg

# 然后对这些帧运行 COLMAP 处理
python convert.py -s /workspace/data/frames
```

***

## 步骤 5 — 训练一个高斯泼溅

### 标准训练

```bash
cd /workspace/gaussian-splatting

python train.py \\
    -s /workspace/data/my_photos \\
    -m /workspace/output/my_scene \\
    --iterations 30000 \\
    --eval
```

### 在 Tandt 数据集上训练

```bash
python train.py \\
    -s /workspace/data/tandt/truck \\
    -m /workspace/output/truck \\
    --iterations 30000 \\
    --eval
```

### 快速训练（快速预览）

```bash
python train.py \\
    -s /workspace/data/my_photos \\
    -m /workspace/output/my_scene_fast \\
    --iterations 7000
```

{% hint style="info" %}
在 RTX 4090 上训练到 7,000 次迭代大约需要 10 分钟，并能给出较高质量的预览。完整的 30,000 次迭代大约需要 30–40 分钟，并产生最终质量结果。
{% endhint %}

### 训练进度

监控训练输出——你会看到如下指标：

```
[ITER 1000] 评估训练集：L1 0.04，PSNR 26.12 dB
[ITER 7000] 评估训练集：L1 0.02，PSNR 29.45 dB
[ITER 30000] 评估训练集：L1 0.01，PSNR 32.80 dB
```

PSNR 高于 30 dB 表示高质量重建。

***

## 步骤 6 — 渲染与可视化

### 从已训练模型渲染

```bash
python render.py \\
    -m /workspace/output/my_scene \\
    --skip_train
```

渲染结果将保存到 `/workspace/output/my_scene/test/ours_30000/renders/`.

### 创建飞行穿越视频

```bash
# 将渲染帧转换为视频
ffmpeg -framerate 24 \\
    -pattern_type glob \\
    -i '/workspace/output/my_scene/test/ours_30000/renders/*.png' \\
    -c:v libx264 \\
    -pix_fmt yuv420p \\
    /workspace/output/flythrough.mp4
```

### 评估指标

```bash
python metrics.py -m /workspace/output/my_scene
```

预期输出：

```
SSIM : 0.8324
PSNR : 32.81
LPIPS: 0.1893
```

***

## 步骤 7 — 交互式网页查看器

要交互式探索已训练的场景：

### 使用 nerfview/viser

```python
# /workspace/view_splat.py
import viser
import numpy as np
from plyfile import PlyData
import torch

server = viser.ViserServer(host="0.0.0.0", port=8080)
print("查看器运行于 http://0.0.0.0:8080")

# 加载 PLY 文件
ply_path = "/workspace/output/my_scene/point_cloud/iteration_30000/point_cloud.ply"
plydata = PlyData.read(ply_path)

xyz = np.stack([
    plydata['vertex']['x'],
    plydata['vertex']['y'],
    plydata['vertex']['z'],
], axis=-1)

# 将点云添加到查看器
server.add_point_cloud(
    name="/splat",
    points=xyz,
    colors=np.ones((len(xyz), 3)) * 0.7,
    point_size=0.003,
)

import time
while True:
    time.sleep(0.01)
```

```bash
python /workspace/view_splat.py &
```

然后打开： `http://<clore-host>:<public-port-8080>`

### 替代方案：使用 SuperSplat（基于浏览器的查看器）

下载 `.ply` 文件并在 [SuperSplat](https://playcanvas.com/super-splat):

```bash
# 从你的本地机器下载
scp -P <port> root@<clore-host>:/workspace/output/my_scene/point_cloud/iteration_30000/point_cloud.ply ./
```

然后将 `.ply` 拖放到 SuperSplat 浏览器中： `https://playcanvas.com/super-splat`

***

## 高级选项

### 控制高斯体数量

```bash
# 为更详细的场景提高致密化程度
python train.py \\
    -s /workspace/data/my_photos \\
    -m /workspace/output/my_scene \\
    --densify_until_iter 15000 \\
    --densify_grad_threshold 0.0002
```

### 白色背景（用于物体）

```bash
python train.py \\
    -s /workspace/data/my_object \\
    -m /workspace/output/my_object \\
    --white_background
```

### 大规模场景

```bash
# 为室外场景增加不透明度重置间隔
python train.py \\
    -s /workspace/data/outdoor \\
    -m /workspace/output/outdoor \\
    --opacity_reset_interval 5000 \\
    --iterations 50000
```

***

## 替代方案：使用 gsplat 的高斯泼溅

`gsplat` 是一种更快、内存效率更高的实现：

```bash
pip install gsplat

# 使用 gsplat 训练
python examples/simple_trainer.py \\
    --data_dir /workspace/data/my_photos \\
    --result_dir /workspace/gsplat_output
```

***

## 故障排查

### CUDA 扩展构建失败

```
error: no kernel image is available for execution on the device
```

**解决方案：** 针对你的特定 GPU 架构重新构建：

```bash
export TORCH_CUDA_ARCH_LIST="8.6"  # 适用于 RTX 3090/4090
cd /workspace/gaussian-splatting
pip install submodules/diff-gaussian-rasterization --force-reinstall
```

### COLMAP 重建失败

**解决方案：**

* 确保图像重叠率 ≥ 50%
* 使用更多照片（推荐 100+ 张）
* 尝试对视频帧使用顺序匹配：添加 `--match sequential` 到 convert.py

### 训练过程中内存不足

```bash
# 减少高斯体的最大数量
python train.py \\
    -s /workspace/data/my_photos \\
    -m /workspace/output/my_scene \\
    --max_num_splats 2000000  # 默认为约 600 万
```

### 场景中的漂浮物

高斯初始化产生的漂浮伪影：

* 增大 `--densify_grad_threshold` 以更具选择性
* 使用 `--prune_opacity_threshold 0.005` 以更早移除低不透明度高斯体

***

## Clore.ai GPU 推荐

高斯泼溅训练对 GPU 计算要求很高，并且频繁调用 CUDA 内核。VRAM 决定最大场景复杂度（高斯体数量）；算力决定训练速度。

| GPU           | 显存    | Clore.ai 价格                       | 30K 次迭代训练  | 最大高斯体数      |
| ------------- | ----- | --------------------------------- | ---------- | ----------- |
| RTX 3090      | 24 GB | $0.07–0.21/小时                     | 约 45–55 分钟 | 约 600 万     |
| RTX 4090      | 24 GB | $0.14–0.42/小时                     | 约 30–35 分钟 | 约 600 万     |
| A100 40GB     | 40 GB | [裸机](https://clore.ai/bare-metal) | 约 12–18 分钟 | 约 1000 万以上  |
| RTX 3080 12GB | 12 GB | $0.05–0.19/小时                     | 约 70 分钟    | 约 300 万（受限） |

{% hint style="info" %}
**RTX 3090，价格为 0.07–0.21 美元/小时，是最佳选择** 用于高斯泼溅。完整的 30K 次迭代训练运行在 GPU 时间上的成本约为 0.09–0.11 美元。对于一次会话中的多个场景，成本几乎可以忽略不计。

快速实验：先训练到 7,000 次迭代（RTX 3090 上约 15 分钟，约 0.03 美元）。在网页查看器中检查质量。只有在最终输出时才运行完整的 30K 次迭代。
{% endhint %}

**COLMAP 预处理说明：** COLMAP（运动结构）在 CPU/GPU 上运行，但主要计算负载在 CPU 上。大多数 Clore.ai 服务器对于少于 200 张图像的场景都配有足够的 CPU。对于 500+ 张图像的数据集，请寻找配备 16 核以上 CPU 的服务器。

***

## 有用资源

* [3D Gaussian Splatting GitHub](https://github.com/graphdeco-inria/gaussian-splatting)
* [原始论文（SIGGRAPH 2023）](https://repo-sam.inria.fr/fungraph/3d-gaussian-splatting/)
* [gsplat — 快速实现](https://github.com/nerfstudio-project/gsplat)
* [SuperSplat — 浏览器查看器](https://playcanvas.com/super-splat)
* [Gaussian Splatting 社区（Reddit）](https://www.reddit.com/r/gaussiansplatting/)
* [Awesome Gaussian Splatting](https://github.com/MrNeRF/awesome-3D-gaussian-splatting)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-zh/3d-sheng-cheng/gaussian-splatting.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
