Allow use of black or white background in Nerfacto models (#1441)

* Allow black/white background color in Nerfacto

* Use white background in Nerfacto Blender Benchmark

* Fixed unused import

* Updated index for license headers script
This commit is contained in:
Sacha Lewin authored and GitHub committed 2023-02-17 20:39:10 -08:00
1 parent 2357332e66
commit 8e4ae6bebf
17 files changed
+14 -22

No files matched your search

+2 -6
View File
@@ -46,7 +46,7 @@ from nerfstudio.model_components.renderers import (
RGBRenderer,
)
from nerfstudio.models.base_model import Model, ModelConfig
from nerfstudio.utils import colormaps, colors
from nerfstudio.utils import colormaps
@dataclass
@@ -123,11 +123,7 @@ class NGPModel(Model):
)
# renderers
background_color = "random"
if self.config.background_color in ["white", "black"]:
background_color = colors.COLORS_DICT[self.config.background_color]
self.renderer_rgb = RGBRenderer(background_color=background_color)
self.renderer_rgb = RGBRenderer(background_color=self.config.background_color)
self.renderer_accumulation = AccumulationRenderer()
self.renderer_depth = DepthRenderer(method="expected")
+1 -1
View File
@@ -68,7 +68,7 @@ class NerfactoModelConfig(ModelConfig):
"""How far along the ray to start sampling."""
far_plane: float = 1000.0
"""How far along the ray to stop sampling."""
background_color: Literal["random", "last_sample"] = "last_sample"
background_color: Literal["random", "last_sample", "black", "white"] = "last_sample"
"""Whether to randomize the background color."""
num_levels: int = 16
"""Number of levels of the hashmap for the base mlp."""
+1 -1
View File
@@ -63,7 +63,7 @@ class NerfplayerNerfactoModelConfig(NerfactoModelConfig):
"""How far along the ray to start sampling."""
far_plane: float = 1000.0
"""How far along the ray to stop sampling."""
background_color: Literal["random", "last_sample"] = "random"
background_color: Literal["random", "last_sample", "black", "white"] = "random"
"""Whether to randomize the background color. (Random is reported to be better on DyCheck.)"""
num_levels: int = 16
"""Hashing grid parameter."""
+2 -10
View File
@@ -42,7 +42,6 @@ from nerfstudio.model_components.renderers import (
)
from nerfstudio.models.base_model import Model
from nerfstudio.models.instant_ngp import InstantNGPModelConfig, NGPModel
from nerfstudio.utils import colors
@dataclass
@@ -128,13 +127,6 @@ class NerfplayerNGPModel(NGPModel):
) # need to update the density_fn later during forward (for input time)
# renderers
self.train_background_color = self.config.train_background_color
self.eval_background_color = self.config.eval_background_color
if self.config.train_background_color in ["white", "black"]:
self.train_background_color = colors.COLORS_DICT[self.config.train_background_color]
if self.config.eval_background_color in ["white", "black"]:
self.eval_background_color = colors.COLORS_DICT[self.config.eval_background_color]
self.renderer_rgb = RGBRenderer() # will update bgcolor later during forward
self.renderer_accumulation = AccumulationRenderer()
self.renderer_depth = DepthRenderer(method="expected")
@@ -175,9 +167,9 @@ class NerfplayerNGPModel(NGPModel):
# update bgcolor in the renderer; usually random color for training and fixed color for inference
if self.training:
self.renderer_rgb.background_color = self.train_background_color
self.renderer_rgb.background_color = self.config.train_background_color
else:
self.renderer_rgb.background_color = self.eval_background_color
self.renderer_rgb.background_color = self.config.eval_background_color
rgb = self.renderer_rgb(
rgb=field_outputs[FieldHeadNames.RGB],
weights=weights,