add option to use random bg color + bg mlp

This commit is contained in:
terrance committed 2023-02-13 21:05:55 +00:00
1 parent 7c40594c37
commit 69b98459a5
2 files changed
+14 -2

No files matched your search

+1
View File
@@ -356,6 +356,7 @@ method_configs["dreamfusion"] = DreamfusionTrainerConfig(
distortion_loss_mult=10, distortion_loss_mult=10,
sphere_collider=True, sphere_collider=True,
initialize_density=False, initialize_density=False,
random_background=True,
interlevel_loss_mult=1.0, interlevel_loss_mult=1.0,
proposal_warmup=500, proposal_warmup=500,
proposal_update_every=5, proposal_update_every=5,
+13 -2
View File
@@ -73,6 +73,8 @@ class DreamFusionModelConfig(ModelConfig):
"""Initial strength of center density""" """Initial strength of center density"""
sphere_collider: bool = True sphere_collider: bool = True
"""Use spherical collider instead of box""" """Use spherical collider instead of box"""
random_background: bool = True
"""Randomly choose between using background mlp and random color for background"""
target_transmittance_start: float = 0.4 target_transmittance_start: float = 0.4
"""target transmittance for opacity penalty. This is the percent of the scene that is """target transmittance for opacity penalty. This is the percent of the scene that is
background when rendered at the start of training""" background when rendered at the start of training"""
@@ -133,6 +135,7 @@ class DreamFusionModel(Model):
self.initialize_density = config.initialize_density self.initialize_density = config.initialize_density
self.train_normals = False self.train_normals = False
self.train_shaded = False self.train_shaded = False
self.random_background = config.random_background
self.density_strength = 1.0 self.density_strength = 1.0
self.target_transmittance = config.target_transmittance_start self.target_transmittance = config.target_transmittance_start
super().__init__(config=config, **kwargs) super().__init__(config=config, **kwargs)
@@ -336,7 +339,7 @@ class DreamFusionModel(Model):
shading_weight = 0.0 shading_weight = 0.0
shaded, shaded_albedo = self.shader_lambertian( shaded, shaded_albedo = self.shader_lambertian(
rgb=rgb, normals=pred_normals, light_direction=light_d, shading_weight=shading_weight, detach_normals=False rgb=rgb, normals=pred_normals, light_direction=light_d, shading_weight=shading_weight, detach_normals=True
) )
outputs["normals"] = self.shader_normals(normals, weights=accum_mask) outputs["normals"] = self.shader_normals(normals, weights=accum_mask)
@@ -347,8 +350,16 @@ class DreamFusionModel(Model):
outputs["rgb"] = accum_mask * rgb + background outputs["rgb"] = accum_mask * rgb + background
if shading_weight > 0: if shading_weight > 0:
if np.random.random_sample() > 0.5 and not self.training: samp = np.random.random_sample()
if samp > 0.5 and not self.training:
outputs["train_output"] = outputs["shaded"] outputs["train_output"] = outputs["shaded"]
elif samp < 0.2 and self.random_background:
rand_bg = torch.zeros(background.shape)
rand_bg.index_fill_(1, torch.tensor([0]), np.random.random_sample())
rand_bg.index_fill_(1, torch.tensor([1]), np.random.random_sample())
rand_bg.index_fill_(1, torch.tensor([2]), np.random.random_sample())
rand_bg = rand_bg.to(self.device)
outputs["train_output"] = accum_mask * shaded_albedo + rand_bg * accum_mask_inv
else: else:
outputs["train_output"] = accum_mask * shaded_albedo + background outputs["train_output"] = accum_mask * shaded_albedo + background
else: else: