mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-01 21:39:06 +08:00
nerf-w and semantic-nerf initial implementations (#73)
* initial nerfw code * nerfw should be implmented correctly now * semantic nerf in progress. data loader is too slow and not clean right now * added implementation of semantic nerf * mend
This commit is contained in:
1 parent
97c9fe2541
commit
1c1a58c4e5
22 files changed
+725
-92
No files matched your search
+19
-12
@@ -22,18 +22,13 @@ class RayBundle:
|
||||
camera_indices: Optional[TensorType["num_rays"]] = None
|
||||
|
||||
def to_camera_ray_bundle(self, image_height, image_width) -> "CameraRayBundle":
|
||||
"""_summary_
|
||||
|
||||
Args:
|
||||
image_height (_type_): _description_
|
||||
image_width (_type_): _description_
|
||||
|
||||
Returns:
|
||||
CameraRayBundle: _description_
|
||||
"""
|
||||
"""Returns a CameraRayBundle from this object."""
|
||||
camera_ray_bundle = CameraRayBundle(
|
||||
origins=self.origins.view(image_height, image_width, 3),
|
||||
directions=self.directions.view(image_height, image_width, 3),
|
||||
camera_indices=self.camera_indices.view(image_height, image_width)
|
||||
if not isinstance(self.camera_indices, type(None))
|
||||
else None,
|
||||
)
|
||||
return camera_ray_bundle
|
||||
|
||||
@@ -77,7 +72,12 @@ class CameraRayBundle:
|
||||
|
||||
def __post_init__(self):
|
||||
if not isinstance(self.camera_index, type(None)):
|
||||
self.camera_indices = torch.ones_like(self.origins[:, :]) * self.camera_index
|
||||
self.set_camera_indices(self.camera_index)
|
||||
|
||||
def set_camera_indices(self, camera_index: int):
|
||||
"""Sets the camera indices for a specific camera index."""
|
||||
self.camera_index = camera_index
|
||||
self.camera_indices = torch.ones_like(self.origins[..., 0]).long() * camera_index
|
||||
|
||||
def get_num_rays(self):
|
||||
"""Return the number of rays in this bundle."""
|
||||
@@ -98,7 +98,7 @@ class CameraRayBundle:
|
||||
def get_row_major_sliced_ray_bundle(self, start_idx, end_idx):
|
||||
"""Return a RayBundle"""
|
||||
camera_indices = (
|
||||
self.camera_indices.view(-1)[start_idx:end_idx] if not isinstance(self.camera_index, type(None)) else None
|
||||
self.camera_indices.view(-1)[start_idx:end_idx] if not isinstance(self.camera_indices, type(None)) else None
|
||||
)
|
||||
return RayBundle(
|
||||
origins=self.origins.view(-1, 3)[start_idx:end_idx],
|
||||
@@ -121,6 +121,12 @@ class RaySamples:
|
||||
self.directions = ray_bundle.directions.unsqueeze(1).repeat(1, self.positions.shape[1], 1)
|
||||
self.deltas = self.get_deltas()
|
||||
|
||||
def get_camera_indices(self):
|
||||
"""Returns camera indices."""
|
||||
assert not isinstance(self.ray_bundle.camera_indices, type(None)), "Camera indices cannot be None here."
|
||||
camera_indices = self.ray_bundle.camera_indices.unsqueeze(1).repeat(1, self.positions.shape[1])
|
||||
return camera_indices
|
||||
|
||||
def get_positions(self, ray_bundle: RayBundle) -> TensorType["num_rays", "num_samples", 3]:
|
||||
"""Returns positions."""
|
||||
return ray_bundle.origins[:, None] + self.ts[:, :, None] * ray_bundle.directions[:, None]
|
||||
@@ -128,7 +134,8 @@ class RaySamples:
|
||||
def get_deltas(self) -> TensorType[..., "num_samples"]:
|
||||
"""Returns deltas."""
|
||||
dists = self.ts[..., 1:] - self.ts[..., :-1]
|
||||
dists = torch.cat([dists, dists[..., -1:]], -1) # [N_rays, N_samples]
|
||||
dist_inf = 1e10 * torch.ones_like(dists[..., -1:])
|
||||
dists = torch.cat([dists, dist_inf], -1) # [N_rays, N_samples]
|
||||
deltas = dists * torch.norm(self.ray_bundle.directions[..., None, :], dim=-1)
|
||||
return deltas
|
||||
|
||||
|
||||
Reference in new issue
Block a user