
MojoSplat:用 Mojo 语言实现 3D Gaussian Splatting 训练与渲染
来源标题:MojoSplat: 3D Gaussian Splatting, training and rendering, written in Mojo
MojoSplat 用纯 Mojo 语言实现了完整的 3D Gaussian Splatting 训练与渲染,从 COLMAP 数据加载到 GPU kernel 均不依赖 Python 或 CUDA C++。该项目旨在验证 Mojo 在单一类 Python 语言中提供 CUDA 级性能、并支持 NVIDIA、AMD 及 Apple GPU 的承诺。使用只需 pixi 和相应 GPU,无需 CUDA 工具包或 Python 环境。
以下正文由 AI 翻译自 Hacker News 最新(原文版权归原站所有),可能存在偏差,重要内容请以原文为准。
完全用 Mojo 编写 3D Gaussian Splatting 的训练与渲染。没有 Python,没有 CUDA C++:从 COLMAP 加载器到 GPU kernel,只用一种语言。
training.mp4
Gaussian Splatting 代码库通常是用 Python 编排手写 CUDA kernel,并绑定在 NVIDIA GPU 上。Mojo 承诺用一门类似 Python 的单一语言实现 CUDA 级性能,同时还能面向 AMD 和 Apple GPU。MojoSplat 是一个完整、快速的 3DGS 实现,用来验证这一承诺。
文档:bertaveira.github.io/mojosplat 包含快速上手、渲染器的图解讲解,以及如何添加新方法。
你只需要 pixi,以及一块 NVIDIA GPU、AMD GPU 或 Apple 芯片的 Mac。不需要 CUDA 工具链、编译器或 Python:pixi 首次运行会把 Mojo 安装到项目文件夹中。只需克隆仓库 git clone https://github.com/bertaveira/mojosplat.git,即可开始。
pixi run train path/to/scene --viewer # 在 http://localhost:8080 观看训练过程
你可以用以下命令评估、查看并渲染训练好的场景:
pixi run eval path/to/scene output/scene/point_cloud.ply pixi run view output/scene/point_cloud.ply pixi run render output/scene/point_cloud.ply -o render.png # 也可渲染 .splat 文件
一个场景就是一个包含 sparse/0/ 和 images_4/ 的 COLMAP 文件夹,例如来自 Mip-NeRF360 的场景。每个超参数都是一个命令行 flag:pixi run train --help。
在 Mac 上,Mojo 使用 Xcode 的 Metal 工具链编译 kernel:用 xcrun metal --version 检查,如果缺失,用 xcodebuild -downloadComponent MetalToolchain 安装。
Mip-NeRF360 garden(images_4,30k 次迭代)。最后四列是各 GPU 上的训练时间。PSNR、SSIM 和 LPIPS 来自 RTX 5090 的运行;RTX 3080 和 Apple M1 Pro 上的 PSNR 误差在 0.1 dB 以内。Faster-GS 使用其官方代码在同一块 RTX 5090 上运行,并用相同的指标代码评分。
- 3DGS 论文的 LPIPS(0.103)不可比较:其评估代码把 [0, 1] 范围的图像传给期望 [-1, 1] 的 LPIPS 网络,导致分数偏低。其他行在正确缩放的图像上使用 LPIPS-VGG。
每种方法(用 --method 选择)还会用其官方代码在七个 Mip-NeRF 360 场景上、同一块 RTX 5090 上训练,并以相同方式评分。表中给出 MojoSplat 每个场景的平均训练时间和渲染速度,括号内是相对官方代码的加速比(低于 1× 表示更慢)。各场景的画质、耗时和公开差异见完整结果。
mojosplat 是一个普通 Mojo 包(pixi run mojo run -I . my_program.mojo):
from max.gpu.host import DeviceContext from mojosplat import Camera, Rasterizer, Splats, download, read_ply, write_png def main() raises: var ctx = DeviceContext() var splats = Splats.from_host(ctx, read_ply("output/garden/point_cloud.ply")) var camera = Camera.translated(0.0, 0.0, 5.0, 1280, 720, 1152.0, 1152.0) var image = ctx.enqueue_create_buffer[DType.float32](1280 * 720 * 3) var rasterizer = Rasterizer(ctx) rasterizer.render(splats, camera, SIMDDType.float32, 4, image) write_png("out.png", download(ctx, image, 1280 * 720 * 3), 1280, 720)
训练是 Trainer(ctx, load_colmap_dataset(ctx, path), TrainConfig()) 和 trainer.step();Rasterizer.forward / backward 可为任意图像损失提供梯度。设计说明见 docs/design.md。
仅限 Linux,在单独的 pixi 环境中:
pixi install -e torch && pixi run -e torch build-ext from mojosplat_torch import Camera, render_splats
原始 3DGS / gsplat 参数:means [N,3],quats [N,4](wxyz),scales [N,3](对数),
opacities [N](logits),sh0 [N,3],shN [N,K,3];float32 CUDA tensor
image = render_splats(means, quats, scales, opacities, sh0, shN, camera) # (H, W, 3) image.mean().backward()
路线图
在 AMD GPU 上验证,并在 AMD 和 Apple GPU 上调优(每个 kernel 已能为两者编译;Apple 上可运行)。 在全部 Mip-NeRF360、Tanks&Temples 和 Deep Blending 场景上跑基准测试。 抗锯齿、更快的优化器选项、Mojo 版 LPIPS。
欢迎贡献;请附带测试(pixi run test)。
MIT 许可。从 Faster-GS(Apache-2.0)、Deformable Beta Splatting(Apache-2.0)、3DGUT(NVIDIA 3dgrut,Apache-2.0)、Spherical Voronoi(MIT)、NeRFICG(MIT)和 fused-ssim(MIT)移植的代码列于 THIRD_PARTY_NOTICES.md。MAX 由 pixi 在 Modular 的 MAX License 下安装。
MojoSplat 的渲染器和训练配方是 Faster-GS(代码)的 Mojo 移植,原作者为 Florian Hahlbohm、Linus Franke、Martin Eisemann 和 Marcus Magnor。如果你使用 MojoSplat,请引用他们的工作:
title = {Faster-GS: Analyzing and Improving Gaussian Splatting Optimization}, author = {Hahlbohm, Florian and Franke, Linus and Eisemann, Martin and Magnor, Marcus}, booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)}, year = {2026}
同时感谢 3D Gaussian Splatting、Taming 3DGS、StopThePop、Splatshop、fused-ssim、gsplat(我们的参考实现)以及 Modular。
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。
