4
0
mirror of https://github.com/nerfstudio-project/nerfstudio.git synced 2026-11-11 10:34:29 +08:00

Merge pull request #116 from ethanweber/tancik/random_backgound_color

Tancik/random backgound color
This commit is contained in:
Matthew Tancik 2022-05-31 10:10:10 -07:00 committed by GitHub
commit 617bf57f97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions

View File

@ -24,7 +24,7 @@ from radiance.utils import visualization, writer
class NGPGraph(Graph):
"""NeRF-W graph"""
"""Instant NGP graph"""
def __init__(self, field_implementation="torch", intrinsics=None, camera_to_world=None, **kwargs) -> None:
assert field_implementation in field_implementation_to_class

View File

@ -17,7 +17,7 @@ class RGBRenderer(nn.Module):
def __init__(self, background_color: Optional[TensorType[3]] = None) -> None:
"""
Args:
background_color (TensorType[3], optional): Background color as RGB. Defaults to black.
background_color (TensorType[3], optional): Background color as RGB. Defaults to random.
"""
super().__init__()
self.background_color = background_color
@ -34,14 +34,17 @@ class RGBRenderer(nn.Module):
Args:
rgb (TensorType[..., "num_samples", -1]): RGB for each sample
weights (TensorType[..., "num_samples"]): Weights for each sample
background_color (TensorType[3], optional): Background color as RGB. Defaults to random.
Returns:
TensorType[..., 3]: Outputs rgb values.
"""
rgb = torch.sum(weights[..., None] * rgb, dim=-2)
if background_color is not None:
rgb = rgb + background_color.to(weights.device)[None, ...] * (1.0 - torch.sum(weights, dim=-1)[..., None])
if background_color is None:
background_color = torch.rand_like(rgb).to(rgb.device)
rgb = rgb + background_color.to(weights.device) * (1.0 - torch.sum(weights, dim=-1)[..., None])
return rgb
@ -74,7 +77,7 @@ class SHRenderer(nn.Module):
) -> None:
"""
Args:
background_color (TensorType[3], optional): Background color as RGB. Defaults to black.
background_color (TensorType[3], optional): Background color as RGB. Defaults to random.
activation (Optional[nn.Module], optional): Output activation. Defaults to Sigmoid().
"""
super().__init__()

View File

@ -21,7 +21,7 @@ def test_rgb_renderer():
assert torch.max(rgb) > 0.9
rgb = rgb_renderer(rgb=rgb_samples * 0, weights=weights)
assert torch.max(rgb) == pytest.approx(0)
assert torch.max(rgb) == pytest.approx(0, abs=1e-6)
def test_sh_renderer():