mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-04 14:58:55 +08:00
Refactoring (data loading, semantic-nerf/nerf-w fixes, ...) (#8)
* in progress. camera_indices broken * faster dataloader. starting on pixel sampler logic * imagesampler and pixelsampler * lint and black * continuing merge * pytest working * fixed docs * docs * minor changes
This commit is contained in:
1 parent
1f189b3e54
commit
146332cfb6
50 files changed
+914
-831
No files matched your search
@@ -98,17 +98,21 @@ class Camera:
|
||||
"""
|
||||
return
|
||||
|
||||
def generate_camera_rays(self) -> RayBundle:
|
||||
def generate_camera_rays(self, device=None) -> RayBundle:
|
||||
"""Generate rays for the camera.
|
||||
|
||||
Returns:
|
||||
Rays: Camera rays of shape [height, width]
|
||||
"""
|
||||
if device is None:
|
||||
device = self.camera_to_world.device
|
||||
height = self.get_image_height()
|
||||
width = self.get_image_width()
|
||||
intrinsics = self.get_intrinsics().unsqueeze(0).repeat(height, width, 1) # (num_rays, num_intrinsics_params)
|
||||
camera_to_world = self.camera_to_world.unsqueeze(0).repeat(height, width, 1, 1) # (num_rays, 3, 4)
|
||||
coords = self.get_image_coords()
|
||||
intrinsics = (
|
||||
self.get_intrinsics().unsqueeze(0).repeat(height, width, 1).to(device)
|
||||
) # (num_rays, num_intrinsics_params)
|
||||
camera_to_world = self.camera_to_world.unsqueeze(0).repeat(height, width, 1, 1).to(device) # (num_rays, 3, 4)
|
||||
coords = self.get_image_coords().to(device)
|
||||
ray_bundle = self.generate_rays(intrinsics, camera_to_world, coords)
|
||||
return ray_bundle
|
||||
|
||||
|
||||
@@ -74,7 +74,12 @@ class RaySamples:
|
||||
def to_point_samples(self) -> PointSamples:
|
||||
"""Convert to PointSamples instance and return."""
|
||||
# TODO: make this more interpretable
|
||||
return PointSamples(positions=self.positions, directions=self.directions, valid_mask=self.valid_mask)
|
||||
return PointSamples(
|
||||
positions=self.positions,
|
||||
directions=self.directions,
|
||||
camera_indices=self.camera_indices,
|
||||
valid_mask=self.valid_mask,
|
||||
)
|
||||
|
||||
def get_weights(self, densities: TensorType[..., "num_samples", 1]) -> TensorType[..., "num_samples"]:
|
||||
"""Return weights based on predicted densities
|
||||
@@ -139,7 +144,7 @@ class RayBundle:
|
||||
"""
|
||||
self.origins = self.origins.to(device)
|
||||
self.directions = self.directions.to(device)
|
||||
if not isinstance(self.camera_indices, type(None)):
|
||||
if is_not_none(self.camera_indices):
|
||||
self.camera_indices = self.camera_indices.to(device)
|
||||
|
||||
def set_camera_indices(self, camera_index: int) -> None:
|
||||
@@ -227,7 +232,7 @@ class RayBundle:
|
||||
dists = torch.cat([dists, dists[..., -1:]], -1) # [N_rays, N_samples]
|
||||
deltas = dists * torch.norm(self.directions[..., None, :], dim=-1)
|
||||
|
||||
if self.camera_indices is not None:
|
||||
if is_not_none(self.camera_indices):
|
||||
camera_indices = self.camera_indices.unsqueeze(1).repeat(1, positions.shape[1])
|
||||
else:
|
||||
camera_indices = None
|
||||
|
||||
Reference in new issue
Block a user