Merge pull request #116 from ethanweber/tancik/random_backgound_color

Tancik/random backgound color
This commit is contained in:
Matthew Tancik authored and GitHub committed 2022-05-31 10:10:10 -07:00
commit 617bf57f97
3 files changed
+9 -6

No files matched your search

+1 -1
View File
@@ -24,7 +24,7 @@ from radiance.utils import visualization, writer
class NGPGraph(Graph): class NGPGraph(Graph):
"""NeRF-W graph""" """Instant NGP graph"""
def __init__(self, field_implementation="torch", intrinsics=None, camera_to_world=None, **kwargs) -> None: def __init__(self, field_implementation="torch", intrinsics=None, camera_to_world=None, **kwargs) -> None:
assert field_implementation in field_implementation_to_class assert field_implementation in field_implementation_to_class
+7 -4
View File
@@ -17,7 +17,7 @@ class RGBRenderer(nn.Module):
def __init__(self, background_color: Optional[TensorType[3]] = None) -> None: def __init__(self, background_color: Optional[TensorType[3]] = None) -> None:
""" """
Args: 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__() super().__init__()
self.background_color = background_color self.background_color = background_color
@@ -34,14 +34,17 @@ class RGBRenderer(nn.Module):
Args: Args:
rgb (TensorType[..., "num_samples", -1]): RGB for each sample rgb (TensorType[..., "num_samples", -1]): RGB for each sample
weights (TensorType[..., "num_samples"]): Weights for each sample weights (TensorType[..., "num_samples"]): Weights for each sample
background_color (TensorType[3], optional): Background color as RGB. Defaults to random.
Returns: Returns:
TensorType[..., 3]: Outputs rgb values. TensorType[..., 3]: Outputs rgb values.
""" """
rgb = torch.sum(weights[..., None] * rgb, dim=-2) rgb = torch.sum(weights[..., None] * rgb, dim=-2)
if background_color is not None: if background_color is None:
rgb = rgb + background_color.to(weights.device)[None, ...] * (1.0 - torch.sum(weights, dim=-1)[..., 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 return rgb
@@ -74,7 +77,7 @@ class SHRenderer(nn.Module):
) -> None: ) -> None:
""" """
Args: 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(). activation (Optional[nn.Module], optional): Output activation. Defaults to Sigmoid().
""" """
super().__init__() super().__init__()
+1 -1
View File
@@ -21,7 +21,7 @@ def test_rgb_renderer():
assert torch.max(rgb) > 0.9 assert torch.max(rgb) > 0.9
rgb = rgb_renderer(rgb=rgb_samples * 0, weights=weights) 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(): def test_sh_renderer():