mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-03 06:18:44 +08:00
CropBox GUI implementation (#1205)
* fixed an exception bug in case of num_samples is 0 fixed an exception bug when num samples is 0 , "IndexError tensors used as indices must be long, byte or bool tensors" change type to long ( was float32) * implemented crop box in gui. For now works on instant-ngp-bounded * fixed import bugs * update aabb every time and not only on training * prevent crash when chosing accomulation and crop box * Checkbox * max_box is bounded by scevne box in the gui * implemented altenative intesection to nerfacc * convert str to bool correctly * fixed isort bug * fixed isort bug2 * update viewer version * remove json bug * Update UI * Force black background * Fix formatting Co-authored-by: dror <you@example.com> Co-authored-by: Matt Tancik <tancik@berkeley.edu> Co-authored-by: Matthew Tancik <mattt4001@gmail.com>
This commit is contained in:
12 files changed
+518
-25
No files matched your search
@@ -449,6 +449,15 @@ class VolumetricSampler(Sampler):
|
||||
|
||||
rays_o = ray_bundle.origins.contiguous()
|
||||
rays_d = ray_bundle.directions.contiguous()
|
||||
|
||||
if ray_bundle.nears is not None and ray_bundle.fars is not None:
|
||||
t_min = ray_bundle.nears.contiguous().reshape(-1)
|
||||
t_max = ray_bundle.fars.contiguous().reshape(-1)
|
||||
|
||||
else:
|
||||
t_min = None
|
||||
t_max = None
|
||||
|
||||
if ray_bundle.camera_indices is not None:
|
||||
camera_indices = ray_bundle.camera_indices.contiguous()
|
||||
else:
|
||||
@@ -457,6 +466,8 @@ class VolumetricSampler(Sampler):
|
||||
ray_indices, starts, ends = nerfacc.ray_marching(
|
||||
rays_o=rays_o,
|
||||
rays_d=rays_d,
|
||||
t_min=t_min,
|
||||
t_max=t_max,
|
||||
scene_aabb=self.scene_aabb,
|
||||
grid=self.occupancy_grid,
|
||||
# this is a workaround - using density causes crash and damage quality. should be fixed
|
||||
|
||||
@@ -26,8 +26,9 @@ Example:
|
||||
rgb = rgb_renderer(rgb=field_outputs[FieldHeadNames.RGB], weights=weights)
|
||||
|
||||
"""
|
||||
import contextlib
|
||||
import math
|
||||
from typing import Optional, Union
|
||||
from typing import Generator, Optional, Union
|
||||
|
||||
import nerfacc
|
||||
import torch
|
||||
@@ -38,6 +39,20 @@ from typing_extensions import Literal
|
||||
from nerfstudio.cameras.rays import RaySamples
|
||||
from nerfstudio.utils.math import components_from_spherical_harmonics
|
||||
|
||||
BACKGROUND_MODE_OVERRIDE: Optional[Literal["last_sample", "black", "random"]] = None
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def background_mode_override_context(mode: Literal["last_sample", "black"]) -> Generator[None, None, None]:
|
||||
"""Context manager for setting background mode."""
|
||||
global BACKGROUND_MODE_OVERRIDE # pylint: disable=global-statement
|
||||
old_background_mode = BACKGROUND_MODE_OVERRIDE
|
||||
try:
|
||||
BACKGROUND_MODE_OVERRIDE = mode
|
||||
yield
|
||||
finally:
|
||||
BACKGROUND_MODE_OVERRIDE = old_background_mode
|
||||
|
||||
|
||||
class RGBRenderer(nn.Module):
|
||||
"""Standard volumetic rendering.
|
||||
@@ -55,7 +70,7 @@ class RGBRenderer(nn.Module):
|
||||
cls,
|
||||
rgb: TensorType["bs":..., "num_samples", 3],
|
||||
weights: TensorType["bs":..., "num_samples", 1],
|
||||
background_color: Union[Literal["random", "last_sample"], TensorType[3]] = "random",
|
||||
background_color: Union[Literal["random", "black", "last_sample"], TensorType[3]] = "random",
|
||||
ray_indices: Optional[TensorType["num_samples"]] = None,
|
||||
num_rays: Optional[int] = None,
|
||||
) -> TensorType["bs":..., 3]:
|
||||
@@ -81,10 +96,14 @@ class RGBRenderer(nn.Module):
|
||||
comp_rgb = torch.sum(weights * rgb, dim=-2)
|
||||
accumulated_weight = torch.sum(weights, dim=-2)
|
||||
|
||||
if BACKGROUND_MODE_OVERRIDE is not None:
|
||||
background_color = BACKGROUND_MODE_OVERRIDE
|
||||
if background_color == "last_sample":
|
||||
background_color = rgb[..., -1, :]
|
||||
if background_color == "random":
|
||||
background_color = torch.rand_like(comp_rgb).to(rgb.device)
|
||||
if background_color == "black":
|
||||
background_color = torch.zeros_like(comp_rgb).to(rgb.device)
|
||||
|
||||
assert isinstance(background_color, torch.Tensor)
|
||||
comp_rgb = comp_rgb + background_color.to(weights.device) * (1.0 - accumulated_weight)
|
||||
|
||||
Reference in new issue
Block a user