mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-06 15:59:16 +08:00
Update to nerfacc 0.0.8 (#471)
This commit is contained in:
1 parent
dc28e463b8
commit
32943caf5b
3 files changed
+35
-24
No files matched your search
@@ -62,9 +62,6 @@ class InstantNGPModelConfig(cfg.ModelConfig):
|
|||||||
"""Instant NGP doesn't use a collider."""
|
"""Instant NGP doesn't use a collider."""
|
||||||
field_implementation: Literal["torch", "tcnn"] = "tcnn" # torch, tcnn, ...
|
field_implementation: Literal["torch", "tcnn"] = "tcnn" # torch, tcnn, ...
|
||||||
"""one of "torch" or "tcnn", or other fields in 'field_implementation_to_class'"""
|
"""one of "torch" or "tcnn", or other fields in 'field_implementation_to_class'"""
|
||||||
# TODO(ethan): remove the density field specified here
|
|
||||||
enable_density_field: bool = False
|
|
||||||
"""Whether to create a density field to filter samples."""
|
|
||||||
num_samples: int = 1024
|
num_samples: int = 1024
|
||||||
"""Number of samples in field evaluation."""
|
"""Number of samples in field evaluation."""
|
||||||
grid_resolution: int = 128
|
grid_resolution: int = 128
|
||||||
@@ -129,7 +126,7 @@ class NGPModel(Model):
|
|||||||
TrainingCallback(
|
TrainingCallback(
|
||||||
where_to_run=[TrainingCallbackLocation.BEFORE_TRAIN_ITERATION],
|
where_to_run=[TrainingCallbackLocation.BEFORE_TRAIN_ITERATION],
|
||||||
update_every_num_iters=1,
|
update_every_num_iters=1,
|
||||||
func=self.sampler.occ_field.every_n_step, # will take in step
|
func=self.sampler.occ_field.every_n_step,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -142,11 +139,10 @@ class NGPModel(Model):
|
|||||||
|
|
||||||
def get_outputs(self, ray_bundle: RayBundle):
|
def get_outputs(self, ray_bundle: RayBundle):
|
||||||
assert self.field is not None
|
assert self.field is not None
|
||||||
|
num_rays = len(ray_bundle)
|
||||||
n_rays = ray_bundle.origins.shape[0]
|
|
||||||
|
|
||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
ray_samples, packed_info = self.sampler(
|
ray_samples, packed_info, ray_indices = self.sampler(
|
||||||
ray_bundle=ray_bundle,
|
ray_bundle=ray_bundle,
|
||||||
near_plane=self.config.near_plane,
|
near_plane=self.config.near_plane,
|
||||||
)
|
)
|
||||||
@@ -154,7 +150,7 @@ class NGPModel(Model):
|
|||||||
field_outputs = self.field(ray_samples)
|
field_outputs = self.field(ray_samples)
|
||||||
|
|
||||||
# accumulation
|
# accumulation
|
||||||
weights, ray_indices = nerfacc.volumetric_rendering_weights(
|
weights = nerfacc.volumetric_rendering_weights(
|
||||||
packed_info=packed_info,
|
packed_info=packed_info,
|
||||||
sigmas=field_outputs[FieldHeadNames.DENSITY],
|
sigmas=field_outputs[FieldHeadNames.DENSITY],
|
||||||
frustum_starts=ray_samples.frustums.starts,
|
frustum_starts=ray_samples.frustums.starts,
|
||||||
@@ -165,10 +161,12 @@ class NGPModel(Model):
|
|||||||
rgb=field_outputs[FieldHeadNames.RGB],
|
rgb=field_outputs[FieldHeadNames.RGB],
|
||||||
weights=weights,
|
weights=weights,
|
||||||
ray_indices=ray_indices,
|
ray_indices=ray_indices,
|
||||||
num_rays=n_rays,
|
num_rays=num_rays,
|
||||||
)
|
)
|
||||||
depth = self.renderer_depth(weights=weights, ray_samples=ray_samples, ray_indices=ray_indices, num_rays=n_rays)
|
depth = self.renderer_depth(
|
||||||
accumulation = self.renderer_accumulation(weights=weights, ray_indices=ray_indices, num_rays=n_rays)
|
weights=weights, ray_samples=ray_samples, ray_indices=ray_indices, num_rays=num_rays
|
||||||
|
)
|
||||||
|
accumulation = self.renderer_accumulation(weights=weights, ray_indices=ray_indices, num_rays=num_rays)
|
||||||
alive_ray_mask = accumulation.squeeze(-1) > 0
|
alive_ray_mask = accumulation.squeeze(-1) > 0
|
||||||
|
|
||||||
outputs = {
|
outputs = {
|
||||||
|
|||||||
@@ -502,7 +502,7 @@ class VolumetricSampler(Sampler):
|
|||||||
num_samples: Optional[int] = None,
|
num_samples: Optional[int] = None,
|
||||||
near_plane: float = 0.0,
|
near_plane: float = 0.0,
|
||||||
remove_occluded_samples: bool = True,
|
remove_occluded_samples: bool = True,
|
||||||
) -> Tuple[RaySamples, TensorType["total_samples", 3]]:
|
) -> Tuple[RaySamples, TensorType["total_samples", 3], TensorType["total_samples", 2]]:
|
||||||
"""Generate ray samples in a bounding box.
|
"""Generate ray samples in a bounding box.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -512,9 +512,10 @@ class VolumetricSampler(Sampler):
|
|||||||
remove_occluded_samples: Whether to remove occluded samples. (requires evaluating the density function)
|
remove_occluded_samples: Whether to remove occluded samples. (requires evaluating the density function)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
a tuple of (ray_samples, packed_info)
|
a tuple of (ray_samples, packed_info, ray_indices)
|
||||||
The ray_samples are packed, only storing the valid samples.
|
The ray_samples are packed, only storing the valid samples.
|
||||||
The packed_info contains all the information to recover packed samples into unpacked mode for rendering.
|
The packed_info contains all the information to recover packed samples into unpacked mode for rendering.
|
||||||
|
The ray_indices contains the indices of the rays that each sample belongs to.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.density_field is not None:
|
if self.density_field is not None:
|
||||||
@@ -528,8 +529,12 @@ class VolumetricSampler(Sampler):
|
|||||||
|
|
||||||
rays_o = ray_bundle.origins.contiguous()
|
rays_o = ray_bundle.origins.contiguous()
|
||||||
rays_d = ray_bundle.directions.contiguous()
|
rays_d = ray_bundle.directions.contiguous()
|
||||||
|
if ray_bundle.camera_indices is not None:
|
||||||
|
camera_indices = ray_bundle.camera_indices.contiguous()
|
||||||
|
else:
|
||||||
|
camera_indices = None
|
||||||
|
|
||||||
packed_info, origins, dirs, starts, ends = nerfacc.volumetric_marching(
|
packed_info, starts, ends = nerfacc.volumetric_marching(
|
||||||
rays_o=rays_o,
|
rays_o=rays_o,
|
||||||
rays_d=rays_d,
|
rays_d=rays_d,
|
||||||
aabb=self.aabb,
|
aabb=self.aabb,
|
||||||
@@ -540,18 +545,25 @@ class VolumetricSampler(Sampler):
|
|||||||
stratified=self.training,
|
stratified=self.training,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ray_indices = nerfacc.unpack_to_ray_indices(packed_info).long()
|
||||||
|
origins = rays_o[ray_indices]
|
||||||
|
dirs = rays_d[ray_indices]
|
||||||
|
if camera_indices is not None:
|
||||||
|
camera_indices = camera_indices[ray_indices]
|
||||||
|
|
||||||
if remove_occluded_samples:
|
if remove_occluded_samples:
|
||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
positions = origins + dirs * (starts + ends) / 2.0
|
positions = origins + dirs * (starts + ends) / 2.0
|
||||||
densities = self.density_fn(positions)
|
densities = self.density_fn(positions)
|
||||||
packed_info, starts, ends, origins, dirs = nerfacc.volumetric_rendering_steps(
|
if camera_indices is not None:
|
||||||
packed_info,
|
packed_info, starts, ends, origins, dirs, camera_indices = nerfacc.volumetric_rendering_steps(
|
||||||
densities,
|
packed_info, densities, starts, ends, origins, dirs, camera_indices
|
||||||
starts,
|
)
|
||||||
ends,
|
else:
|
||||||
origins,
|
packed_info, starts, ends, origins, dirs = nerfacc.volumetric_rendering_steps(
|
||||||
dirs,
|
packed_info, densities, starts, ends, origins, dirs
|
||||||
)
|
)
|
||||||
|
ray_indices = nerfacc.unpack_to_ray_indices(packed_info).long()
|
||||||
|
|
||||||
zeros = torch.zeros_like(origins[:, :1])
|
zeros = torch.zeros_like(origins[:, :1])
|
||||||
ray_samples = RaySamples(
|
ray_samples = RaySamples(
|
||||||
@@ -562,5 +574,6 @@ class VolumetricSampler(Sampler):
|
|||||||
ends=ends,
|
ends=ends,
|
||||||
pixel_area=zeros,
|
pixel_area=zeros,
|
||||||
),
|
),
|
||||||
|
camera_indices=camera_indices,
|
||||||
)
|
)
|
||||||
return ray_samples, packed_info
|
return ray_samples, packed_info, ray_indices
|
||||||
+1
-1
@@ -33,7 +33,7 @@ dependencies = [
|
|||||||
"mediapy==1.1.0",
|
"mediapy==1.1.0",
|
||||||
"msgpack==1.0.4",
|
"msgpack==1.0.4",
|
||||||
"msgpack_numpy==0.4.8",
|
"msgpack_numpy==0.4.8",
|
||||||
"nerfacc==0.0.6",
|
"nerfacc==0.0.8",
|
||||||
"numpy-quaternion",
|
"numpy-quaternion",
|
||||||
"opencv-python==4.6.0.66",
|
"opencv-python==4.6.0.66",
|
||||||
"plotly==5.7.0",
|
"plotly==5.7.0",
|
||||||
|
|||||||
Reference in new issue
Block a user