From 05ce76db9902827d2d9ad1556f8d3f563c7daa11 Mon Sep 17 00:00:00 2001 From: Otto Seiskari Date: Thu, 28 Mar 2024 21:03:53 +0200 Subject: [PATCH] Get rid of redundant projection matrix computations in Splatfacto (needs a gsplat update) (#3019) Get rid of projection matrix in ProjectGaussians with gsplat >= 0.1.9 --- nerfstudio/models/splatfacto.py | 25 ------------------------- pyproject.toml | 2 +- 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/nerfstudio/models/splatfacto.py b/nerfstudio/models/splatfacto.py index aaf2c0915..7d7a78d2d 100644 --- a/nerfstudio/models/splatfacto.py +++ b/nerfstudio/models/splatfacto.py @@ -79,27 +79,6 @@ def SH2RGB(sh): return sh * C0 + 0.5 -def projection_matrix(znear, zfar, fovx, fovy, device: Union[str, torch.device] = "cpu"): - """ - Constructs an OpenGL-style perspective projection matrix. - """ - t = znear * math.tan(0.5 * fovy) - b = -t - r = znear * math.tan(0.5 * fovx) - l = -r - n = znear - f = zfar - return torch.tensor( - [ - [2 * n / (r - l), 0.0, (r + l) / (r - l), 0.0], - [0.0, 2 * n / (t - b), (t + b) / (t - b), 0.0], - [0.0, 0.0, (f + n) / (f - n), -1.0 * f * n / (f - n)], - [0.0, 0.0, 1.0, 0.0], - ], - device=device, - ) - - @dataclass class SplatfactoModelConfig(ModelConfig): """Splatfacto Model Config, nerfstudio's implementation of Gaussian Splatting""" @@ -709,11 +688,8 @@ class SplatfactoModel(Model): # calculate the FOV of the camera given fx and fy, width and height cx = camera.cx.item() cy = camera.cy.item() - fovx = 2 * math.atan(camera.width / (2 * camera.fx)) - fovy = 2 * math.atan(camera.height / (2 * camera.fy)) W, H = int(camera.width.item()), int(camera.height.item()) self.last_size = (H, W) - projmat = projection_matrix(0.001, 1000, fovx, fovy, device=self.device) if crop_ids is not None: opacities_crop = self.opacities[crop_ids] @@ -738,7 +714,6 @@ class SplatfactoModel(Model): 1, quats_crop / quats_crop.norm(dim=-1, keepdim=True), viewmat.squeeze()[:3, :], - projmat.squeeze() @ viewmat.squeeze(), camera.fx.item(), camera.fy.item(), cx, diff --git a/pyproject.toml b/pyproject.toml index a181b5c11..376c194b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,7 +63,7 @@ dependencies = [ "xatlas", "trimesh>=3.20.2", "timm==0.6.7", - "gsplat>=0.1.6", + "gsplat>=0.1.9", "pytorch-msssim", "pathos", "packaging"