params, add random background

This commit is contained in:
Justin Kerr committed 2023-09-28 17:47:37 -07:00
1 parent ef7f9b7cf2
commit d6c49d3f90
2 files changed
+12 -8

No files matched your search

+1 -1
View File
@@ -596,7 +596,7 @@ method_configs["gaussian-splatting"] = TrainerConfig(
mixed_precision=False, mixed_precision=False,
pipeline=VanillaPipelineConfig( pipeline=VanillaPipelineConfig(
datamanager=FullImageDatamanagerConfig( datamanager=FullImageDatamanagerConfig(
dataparser=ColmapDataParserConfig(load_3D_points=True,downscale_factor=1), dataparser=ColmapDataParserConfig(load_3D_points=True),
), ),
model=GaussianSplattingModelConfig(), model=GaussianSplattingModelConfig(),
), ),
@@ -99,10 +99,10 @@ class GaussianSplattingModelConfig(ModelConfig):
"""Every this many refinement steps, reset the alpha""" """Every this many refinement steps, reset the alpha"""
densify_grad_thresh: float = .0002 densify_grad_thresh: float = .0002
"""threshold of positional gradient norm for densifying gaussians""" """threshold of positional gradient norm for densifying gaussians"""
densify_size_thresh: float = .007 densify_size_thresh: float = .01
"""below this size, gaussians are *duplicated*, otherwise split""" """below this size, gaussians are *duplicated*, otherwise split"""
#set to 3 to effeectively turn off, it seems to make things worse? need to investigate #set to 3 to effeectively turn off, it seems to make things worse? need to investigate
sh_degree_interval: int = 500 sh_degree_interval: int = 3
"""every n intervals turn on another sh degree""" """every n intervals turn on another sh degree"""
class GaussianSplattingModel(Model): class GaussianSplattingModel(Model):
@@ -149,6 +149,7 @@ class GaussianSplattingModel(Model):
del optimizer.state[param] del optimizer.state[param]
optimizer.state[param] = param_state optimizer.state[param] = param_state
optimizer.param_groups[0]['params'] = new_params optimizer.param_groups[0]['params'] = new_params
del param
def dup_in_optim(self,optimizer, dup_mask, new_params): def dup_in_optim(self,optimizer, dup_mask, new_params):
"""adds the parameters to the optimizer""" """adds the parameters to the optimizer"""
@@ -159,6 +160,7 @@ class GaussianSplattingModel(Model):
del optimizer.state[param] del optimizer.state[param]
optimizer.state[param] = param_state optimizer.state[param] = param_state
optimizer.param_groups[0]['params'] = new_params optimizer.param_groups[0]['params'] = new_params
del param
def after_train(self,step): def after_train(self,step):
with torch.no_grad(): with torch.no_grad():
@@ -171,6 +173,7 @@ class GaussianSplattingModel(Model):
def refinement_before(self, optimizers:Optimizers, step): def refinement_before(self, optimizers:Optimizers, step):
print("Inside refinement before") print("Inside refinement before")
if self.step > self.config.warmup_length: if self.step > self.config.warmup_length:
with torch.no_grad():
# do all the refinement stuff here # do all the refinement stuff here
#first we cull gaussians #first we cull gaussians
deleted_mask = self.cull_gaussians() deleted_mask = self.cull_gaussians()
@@ -181,6 +184,7 @@ class GaussianSplattingModel(Model):
def refinement_after(self, optimizers:Optimizers, step): def refinement_after(self, optimizers:Optimizers, step):
if self.step > self.config.warmup_length: if self.step > self.config.warmup_length:
with torch.no_grad():
#then we densify #then we densify
high_grads = (self.means_grad_norm > self.config.densify_grad_thresh).squeeze() high_grads = (self.means_grad_norm > self.config.densify_grad_thresh).squeeze()
splits = (self.scales.exp().max(dim=-1).values > self.config.densify_size_thresh).squeeze() splits = (self.scales.exp().max(dim=-1).values > self.config.densify_size_thresh).squeeze()
@@ -208,7 +212,6 @@ class GaussianSplattingModel(Model):
if self.step // self.config.refine_every % self.config.reset_alpha_every == 0: if self.step // self.config.refine_every % self.config.reset_alpha_every == 0:
print("Resetting alpha") print("Resetting alpha")
with torch.no_grad():
reset_value = .01 reset_value = .01
self.opacities.data = torch.full_like(self.opacities.data,torch.logit(torch.tensor(reset_value)).item()) self.opacities.data = torch.full_like(self.opacities.data,torch.logit(torch.tensor(reset_value)).item())
self.means_grad_norm = None self.means_grad_norm = None
@@ -218,7 +221,6 @@ class GaussianSplattingModel(Model):
This function deletes gaussians with under a certain opacity threshold This function deletes gaussians with under a certain opacity threshold
""" """
n_bef = self.num_points n_bef = self.num_points
with torch.no_grad():
#cull transparent ones #cull transparent ones
culls = (torch.sigmoid(self.opacities) < self.config.cull_alpha_thresh).squeeze() culls = (torch.sigmoid(self.opacities) < self.config.cull_alpha_thresh).squeeze()
#cull huge ones #cull huge ones
@@ -237,7 +239,6 @@ class GaussianSplattingModel(Model):
""" """
This function splits gaussians that are too large This function splits gaussians that are too large
""" """
with torch.no_grad():
n_splits = split_mask.sum().item() n_splits = split_mask.sum().item()
print(f"Splitting {split_mask.sum().item()/self.num_points} gaussians: {n_splits}/{self.num_points}") print(f"Splitting {split_mask.sum().item()/self.num_points} gaussians: {n_splits}/{self.num_points}")
#step 1, sample new means #step 1, sample new means
@@ -371,7 +372,10 @@ class GaussianSplattingModel(Model):
(H + BLOCK_Y - 1) // BLOCK_Y, (H + BLOCK_Y - 1) // BLOCK_Y,
1, 1,
) )
background = torch.ones(3, device=self.device) if self.training:
background = torch.rand(3, device=self.device)
else:
background = torch.zeros(3, device=self.device)
xys, depths, radii, conics, num_tiles_hit,self.cov3d = ProjectGaussians.apply( xys, depths, radii, conics, num_tiles_hit,self.cov3d = ProjectGaussians.apply(
self.means, self.means,
torch.exp(self.scales), torch.exp(self.scales),
@@ -438,7 +442,7 @@ class GaussianSplattingModel(Model):
gt_img = batch['image'] gt_img = batch['image']
Ll1 = torch.nn.functional.l1_loss(gt_img, outputs['rgb']) Ll1 = torch.nn.functional.l1_loss(gt_img, outputs['rgb'])
# This simloss makes the results look weird, removing for now # This simloss makes the results look weird, removing for now
# simloss = self.ssim(batch['image'].permute(2,0,1)[None,...], outputs['rgb'].permute(2,0,1)[None,...]) simloss = self.ssim(gt_img.permute(2,0,1)[None,...], outputs['rgb'].permute(2,0,1)[None,...])
return {"main_loss": Ll1} return {"main_loss": Ll1}
@torch.no_grad() @torch.no_grad()