forked from graphdeco-inria/gaussian-splatting
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,099 additions
and
552 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,16 +9,17 @@ | |
# For inquiries contact [email protected] | ||
# | ||
|
||
from argparse import ArgumentParser, Namespace | ||
import sys | ||
import os | ||
import sys | ||
from argparse import ArgumentParser, Namespace | ||
|
||
|
||
class GroupParams: | ||
pass | ||
|
||
|
||
class ParamGroup: | ||
def __init__(self, parser: ArgumentParser = None, name : str = "", fill_none = False): | ||
def __init__(self, parser: ArgumentParser = None, name: str = "", fill_none=False): | ||
if parser is None: | ||
parser = ArgumentParser() | ||
group = parser.add_argument_group(name) | ||
|
@@ -31,9 +32,13 @@ def __init__(self, parser: ArgumentParser = None, name : str = "", fill_none = F | |
value = value if not fill_none else None | ||
if shorthand: | ||
if t == bool: | ||
group.add_argument("--" + key, ("-" + key[0:1]), default=value, action="store_true") | ||
group.add_argument( | ||
"--" + key, ("-" + key[0:1]), default=value, action="store_true" | ||
) | ||
else: | ||
group.add_argument("--" + key, ("-" + key[0:1]), default=value, type=t) | ||
group.add_argument( | ||
"--" + key, ("-" + key[0:1]), default=value, type=t | ||
) | ||
else: | ||
if t == bool: | ||
group.add_argument("--" + key, default=value, action="store_true") | ||
|
@@ -47,6 +52,7 @@ def extract(self, args): | |
setattr(group, arg[0], arg[1]) | ||
return group | ||
|
||
|
||
class ModelParams(ParamGroup): | ||
def __init__(self, parser=None, source_path="", sentinel=False): | ||
self.sh_degree = 3 | ||
|
@@ -62,6 +68,7 @@ def extract(self, args): | |
g.source_path = os.path.abspath(g.source_path) | ||
return g | ||
|
||
|
||
class OptimizationParams(ParamGroup): | ||
def __init__(self, parser=None): | ||
self.iterations = 30_000 | ||
|
@@ -82,7 +89,8 @@ def __init__(self, parser=None): | |
self.densify_grad_threshold = 0.0002 | ||
super().__init__(parser, "Optimization Parameters") | ||
|
||
def get_combined_args(parser : ArgumentParser): | ||
|
||
def get_combined_args(parser: ArgumentParser): | ||
cmdlne_string = sys.argv[1:] | ||
cfgfile_string = "Namespace()" | ||
args_cmdline = parser.parse_args(cmdlne_string) | ||
|
@@ -99,7 +107,7 @@ def get_combined_args(parser : ArgumentParser): | |
args_cfgfile = eval(cfgfile_string) | ||
|
||
merged_dict = vars(args_cfgfile).copy() | ||
for k,v in vars(args_cmdline).items(): | ||
for k, v in vars(args_cmdline).items(): | ||
if v != None: | ||
merged_dict[k] = v | ||
return Namespace(**merged_dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,21 +9,36 @@ | |
# For inquiries contact [email protected] | ||
# | ||
|
||
import torch | ||
import math | ||
from diff_gaussian_rasterization import GaussianRasterizationSettings, GaussianRasterizer | ||
|
||
import torch | ||
from diff_gaussian_rasterization import ( | ||
GaussianRasterizationSettings, | ||
GaussianRasterizer, | ||
) | ||
|
||
from gaussian_splatting.scene.gaussian_model import GaussianModel | ||
from gaussian_splatting.utils.sh_utils import eval_sh | ||
|
||
def render(viewpoint_camera, pc : GaussianModel, bg_color : torch.Tensor = None, scaling_modifier = 1.0): | ||
|
||
def render( | ||
viewpoint_camera, | ||
pc: GaussianModel, | ||
bg_color: torch.Tensor = None, | ||
scaling_modifier=1.0, | ||
): | ||
""" | ||
Render the scene. | ||
Background tensor (bg_color) must be on GPU! | ||
""" | ||
|
||
# Create zero tensor. We will use it to make pytorch return gradients of the 2D (screen-space) means | ||
screenspace_points = torch.zeros_like(pc.get_xyz, dtype=pc.get_xyz.dtype, requires_grad=True, device="cuda") + 0 | ||
screenspace_points = ( | ||
torch.zeros_like( | ||
pc.get_xyz, dtype=pc.get_xyz.dtype, requires_grad=True, device="cuda" | ||
) | ||
+ 0 | ||
) | ||
try: | ||
screenspace_points.retain_grad() | ||
except: | ||
|
@@ -48,7 +63,7 @@ def render(viewpoint_camera, pc : GaussianModel, bg_color : torch.Tensor = None, | |
sh_degree=pc.active_sh_degree, | ||
campos=viewpoint_camera.camera_center, | ||
prefiltered=False, | ||
debug=False | ||
debug=False, | ||
) | ||
|
||
rasterizer = GaussianRasterizer(raster_settings=raster_settings) | ||
|
@@ -68,18 +83,21 @@ def render(viewpoint_camera, pc : GaussianModel, bg_color : torch.Tensor = None, | |
|
||
# Rasterize visible Gaussians to image, obtain their radii (on screen). | ||
rendered_image, radii = rasterizer( | ||
means3D = means3D, | ||
means2D = means2D, | ||
shs = shs, | ||
colors_precomp = colors_precomp, | ||
opacities = opacity, | ||
scales = scales, | ||
rotations = rotations, | ||
cov3D_precomp = cov3D_precomp) | ||
means3D=means3D, | ||
means2D=means2D, | ||
shs=shs, | ||
colors_precomp=colors_precomp, | ||
opacities=opacity, | ||
scales=scales, | ||
rotations=rotations, | ||
cov3D_precomp=cov3D_precomp, | ||
) | ||
|
||
# Those Gaussians that were frustum culled or had a radius of 0 were not visible. | ||
# They will be excluded from value updates used in the splitting criteria. | ||
return {"render": rendered_image, | ||
"viewspace_points": screenspace_points, | ||
"visibility_filter" : radii > 0, | ||
"radii": radii} | ||
return { | ||
"render": rendered_image, | ||
"viewspace_points": screenspace_points, | ||
"visibility_filter": radii > 0, | ||
"radii": radii, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.