mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-05 15:28:49 +08:00
Add temporal distortion and D-NeRF model (#825)
* Add D-NeRF temporal distortion and D-NeRF model This allows for temporal distortion to be enabled on a variety of models through config parameters, without an explicit model. Temporal distortion and MIP-NeRF are not currently jointly runnable but can be changed in the future. * Simplifying changes * Simplifying changes Co-authored-by: Matthew Tancik <tancik@berkeley.edu>
This commit is contained in:
1 parent
8678f4c2e6
commit
9ff167d705
9 files changed
+206
-7
No files matched your search
@@ -337,8 +337,14 @@ class Cameras:
|
||||
else:
|
||||
ray_bundle_camera_indices = camera_indices.view(pixel_area.shape)
|
||||
|
||||
times = self.times[camera_indices, None] if self.times is not None else None
|
||||
|
||||
return RayBundle(
|
||||
origins=origins, directions=directions, pixel_area=pixel_area, camera_indices=ray_bundle_camera_indices
|
||||
origins=origins,
|
||||
directions=directions,
|
||||
pixel_area=pixel_area,
|
||||
camera_indices=ray_bundle_camera_indices,
|
||||
times=times,
|
||||
)
|
||||
|
||||
def to_json(
|
||||
@@ -362,7 +368,7 @@ class Cameras:
|
||||
"fy": self.fy[camera_idx].tolist(),
|
||||
"camera_to_world": self.camera_to_worlds[camera_idx].tolist(),
|
||||
"camera_index": camera_idx,
|
||||
"times": self.times[camera_idx] if self.times is not None else None,
|
||||
"times": self.times[camera_idx].item() if self.times is not None else None,
|
||||
}
|
||||
if image is not None:
|
||||
image_uint8 = (image * 255).detach().type(torch.uint8)
|
||||
|
||||
@@ -40,6 +40,8 @@ class Frustums(TensorDataclass):
|
||||
"""Where the frustum ends along a ray."""
|
||||
pixel_area: TensorType["bs":..., 1]
|
||||
"""Projected area of pixel a distance 1 away from origin."""
|
||||
offsets: Optional[TensorType["bs":..., 3]] = None
|
||||
"""Offsets for each sample position"""
|
||||
|
||||
def get_positions(self) -> TensorType[..., 3]:
|
||||
"""Calulates "center" position of frustum. Not weighted by mass.
|
||||
@@ -47,7 +49,14 @@ class Frustums(TensorDataclass):
|
||||
Returns:
|
||||
xyz positions.
|
||||
"""
|
||||
return self.origins + self.directions * (self.starts + self.ends) / 2
|
||||
pos = self.origins + self.directions * (self.starts + self.ends) / 2
|
||||
if self.offsets is not None:
|
||||
pos = pos + self.offsets
|
||||
return pos
|
||||
|
||||
def set_offsets(self, offsets):
|
||||
"""Sets offsets for this frustum for computing positions"""
|
||||
self.offsets = offsets
|
||||
|
||||
def get_gaussian_blob(self) -> Gaussians:
|
||||
"""Calculates guassian approximation of conical frustum.
|
||||
@@ -57,6 +66,8 @@ class Frustums(TensorDataclass):
|
||||
"""
|
||||
# Cone radius is set such that the square pixel_area matches the cone area.
|
||||
cone_radius = torch.sqrt(self.pixel_area) / 1.7724538509055159 # r = sqrt(pixel_area / pi)
|
||||
if self.offsets is not None:
|
||||
raise NotImplementedError()
|
||||
return conical_frustum_to_gaussian(
|
||||
origins=self.origins,
|
||||
directions=self.directions,
|
||||
@@ -100,6 +111,9 @@ class RaySamples(TensorDataclass):
|
||||
metadata: Optional[Dict[str, TensorType["bs":..., "latent_dims"]]] = None
|
||||
"""addtional information relevant to generating ray samples"""
|
||||
|
||||
times: Optional[TensorType[..., 1]] = None
|
||||
"""Times at which rays are sampled"""
|
||||
|
||||
def get_weights(self, densities: TensorType[..., "num_samples", 1]) -> TensorType[..., "num_samples", 1]:
|
||||
"""Return weights based on predicted densities
|
||||
|
||||
@@ -143,6 +157,8 @@ class RayBundle(TensorDataclass):
|
||||
"""Rays Distance along ray to stop sampling"""
|
||||
metadata: Optional[Dict[str, TensorType["num_rays", "latent_dims"]]] = None
|
||||
"""Additional metadata or data needed for interpolation, will mimic shape of rays"""
|
||||
times: Optional[TensorType[..., 1]] = None
|
||||
"""Times at which rays are sampled"""
|
||||
|
||||
def set_camera_indices(self, camera_index: int) -> None:
|
||||
"""Sets all of the the camera indices to a specific camera index.
|
||||
@@ -223,6 +239,7 @@ class RayBundle(TensorDataclass):
|
||||
spacing_ends=spacing_ends, # [..., num_samples, 1]
|
||||
spacing_to_euclidean_fn=spacing_to_euclidean_fn,
|
||||
metadata=shaped_raybundle_fields.metadata,
|
||||
times=None if self.times is None else self.times[..., None], # [..., 1, 1]
|
||||
)
|
||||
|
||||
return ray_samples
|
||||
Reference in new issue
Block a user