Spaces:
Runtime error
Runtime error
Stanislaw Szymanowicz
commited on
Commit
·
11ffd30
1
Parent(s):
053a219
Remove rendering
Browse files- gaussian_renderer/__init__.py +0 -105
gaussian_renderer/__init__.py
DELETED
|
@@ -1,105 +0,0 @@
|
|
| 1 |
-
# Adapted from https://github.com/graphdeco-inria/gaussian-splatting/tree/main
|
| 2 |
-
# to take in a predicted dictionary with 3D Gaussian parameters.
|
| 3 |
-
|
| 4 |
-
import math
|
| 5 |
-
import torch
|
| 6 |
-
import numpy as np
|
| 7 |
-
import os
|
| 8 |
-
|
| 9 |
-
try:
|
| 10 |
-
from diff_gaussian_rasterization import GaussianRasterizationSettings, GaussianRasterizer
|
| 11 |
-
except ImportError:
|
| 12 |
-
os.system("pip install git+https://github.com/graphdeco-inria/diff-gaussian-rasterization")
|
| 13 |
-
from diff_gaussian_rasterization import GaussianRasterizationSettings, GaussianRasterizer
|
| 14 |
-
|
| 15 |
-
from utils.graphics_utils import focal2fov
|
| 16 |
-
|
| 17 |
-
def render_predicted(pc : dict,
|
| 18 |
-
world_view_transform,
|
| 19 |
-
full_proj_transform,
|
| 20 |
-
camera_center,
|
| 21 |
-
bg_color : torch.Tensor,
|
| 22 |
-
cfg,
|
| 23 |
-
scaling_modifier = 1.0,
|
| 24 |
-
override_color = None,
|
| 25 |
-
focals_pixels = None):
|
| 26 |
-
"""
|
| 27 |
-
Render the scene as specified by pc dictionary.
|
| 28 |
-
|
| 29 |
-
Background tensor (bg_color) must be on GPU!
|
| 30 |
-
"""
|
| 31 |
-
|
| 32 |
-
# Create zero tensor. We will use it to make pytorch return gradients of the 2D (screen-space) means
|
| 33 |
-
screenspace_points = torch.zeros_like(pc["xyz"], dtype=pc["xyz"].dtype, requires_grad=True, device="cuda") + 0
|
| 34 |
-
try:
|
| 35 |
-
screenspace_points.retain_grad()
|
| 36 |
-
except:
|
| 37 |
-
pass
|
| 38 |
-
|
| 39 |
-
if focals_pixels == None:
|
| 40 |
-
tanfovx = math.tan(cfg.data.fov * np.pi / 360)
|
| 41 |
-
tanfovy = math.tan(cfg.data.fov * np.pi / 360)
|
| 42 |
-
else:
|
| 43 |
-
tanfovx = math.tan(0.5 * focal2fov(focals_pixels[0].item(), cfg.data.training_resolution))
|
| 44 |
-
tanfovy = math.tan(0.5 * focal2fov(focals_pixels[1].item(), cfg.data.training_resolution))
|
| 45 |
-
|
| 46 |
-
# Set up rasterization configuration
|
| 47 |
-
raster_settings = GaussianRasterizationSettings(
|
| 48 |
-
image_height=int(cfg.data.training_resolution),
|
| 49 |
-
image_width=int(cfg.data.training_resolution),
|
| 50 |
-
tanfovx=tanfovx,
|
| 51 |
-
tanfovy=tanfovy,
|
| 52 |
-
bg=bg_color,
|
| 53 |
-
scale_modifier=scaling_modifier,
|
| 54 |
-
viewmatrix=world_view_transform,
|
| 55 |
-
projmatrix=full_proj_transform,
|
| 56 |
-
sh_degree=cfg.model.max_sh_degree,
|
| 57 |
-
campos=camera_center,
|
| 58 |
-
prefiltered=False,
|
| 59 |
-
debug=False
|
| 60 |
-
)
|
| 61 |
-
|
| 62 |
-
rasterizer = GaussianRasterizer(raster_settings=raster_settings)
|
| 63 |
-
|
| 64 |
-
means3D = pc["xyz"]
|
| 65 |
-
means2D = screenspace_points
|
| 66 |
-
opacity = pc["opacity"]
|
| 67 |
-
|
| 68 |
-
# If precomputed 3d covariance is provided, use it. If not, then it will be computed from
|
| 69 |
-
# scaling / rotation by the rasterizer.
|
| 70 |
-
scales = None
|
| 71 |
-
rotations = None
|
| 72 |
-
cov3D_precomp = None
|
| 73 |
-
|
| 74 |
-
scales = pc["scaling"]
|
| 75 |
-
rotations = pc["rotation"]
|
| 76 |
-
|
| 77 |
-
# If precomputed colors are provided, use them. Otherwise, if it is desired to precompute colors
|
| 78 |
-
# from SHs in Python, do it. If not, then SH -> RGB conversion will be done by rasterizer.
|
| 79 |
-
shs = None
|
| 80 |
-
colors_precomp = None
|
| 81 |
-
if override_color is None:
|
| 82 |
-
if "features_rest" in pc.keys():
|
| 83 |
-
shs = torch.cat([pc["features_dc"], pc["features_rest"]], dim=1).contiguous()
|
| 84 |
-
else:
|
| 85 |
-
shs = pc["features_dc"]
|
| 86 |
-
else:
|
| 87 |
-
colors_precomp = override_color
|
| 88 |
-
|
| 89 |
-
# Rasterize visible Gaussians to image, obtain their radii (on screen).
|
| 90 |
-
rendered_image, radii = rasterizer(
|
| 91 |
-
means3D = means3D,
|
| 92 |
-
means2D = means2D,
|
| 93 |
-
shs = shs,
|
| 94 |
-
colors_precomp = colors_precomp,
|
| 95 |
-
opacities = opacity,
|
| 96 |
-
scales = scales,
|
| 97 |
-
rotations = rotations,
|
| 98 |
-
cov3D_precomp = cov3D_precomp)
|
| 99 |
-
|
| 100 |
-
# Those Gaussians that were frustum culled or had a radius of 0 were not visible.
|
| 101 |
-
# They will be excluded from value updates used in the splitting criteria.
|
| 102 |
-
return {"render": rendered_image,
|
| 103 |
-
"viewspace_points": screenspace_points,
|
| 104 |
-
"visibility_filter" : radii > 0,
|
| 105 |
-
"radii": radii}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|