mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-30 04:50:16 +08:00
Camera Refactor (#301)
* Start camera refactor * Training runs, but transforms incorrect * Cameras render correctly in viewer. * Fix eval * cleanup * cleanup
This commit is contained in:
1 parent
6bdb26c3a4
commit
04d0165a24
15 files changed
+334
-614
No files matched your search
@@ -26,7 +26,6 @@ import torch
|
||||
from torch import nn
|
||||
from torch.nn import Parameter
|
||||
|
||||
from nerfactory.cameras.cameras import Camera
|
||||
from nerfactory.cameras.rays import RayBundle
|
||||
from nerfactory.configs import base as cfg
|
||||
from nerfactory.dataloaders.structs import SceneBounds
|
||||
@@ -198,11 +197,6 @@ class Model(nn.Module):
|
||||
outputs[output_name] = torch.cat(outputs_list).view(image_height, image_width, -1) # type: ignore
|
||||
return outputs
|
||||
|
||||
def get_outputs_for_camera(self, camera: Camera):
|
||||
"""Get the model outputs for a Camera."""
|
||||
camera_ray_bundle = camera.get_camera_ray_bundle(device=self.device)
|
||||
return self.get_outputs_for_camera_ray_bundle(camera_ray_bundle)
|
||||
|
||||
@abstractmethod
|
||||
def log_test_image_outputs(self, image_idx, step, batch, outputs) -> float:
|
||||
"""Writes the test image outputs.
|
||||
|
||||
@@ -18,7 +18,7 @@ Ray generator.
|
||||
from torch import nn
|
||||
from torchtyping import TensorType
|
||||
|
||||
from nerfactory.cameras.cameras import get_camera_model
|
||||
from nerfactory.cameras.cameras import Cameras
|
||||
from nerfactory.cameras.rays import RayBundle
|
||||
|
||||
|
||||
@@ -31,23 +31,10 @@ class RayGenerator(nn.Module):
|
||||
camera_to_world: Camera to world transformation matrix.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
intrinsics: TensorType["num_cameras", "num_intrinsics_params"],
|
||||
camera_to_world: TensorType["num_cameras", 3, 4],
|
||||
) -> None:
|
||||
def __init__(self, cameras: Cameras) -> None:
|
||||
super().__init__()
|
||||
self.num_cameras, self.num_intrinsics_params = intrinsics.shape
|
||||
assert self.num_cameras >= 0
|
||||
self.intrinsics = nn.Parameter(intrinsics, requires_grad=False)
|
||||
self.camera_to_world = nn.Parameter(camera_to_world, requires_grad=False)
|
||||
# TODO(ethan): add learnable parameters that are deltas on the intrinsics and camera_to_world parameters
|
||||
|
||||
# NOTE(ethan): we currently assume all images have the same height and width
|
||||
camera_index = 0
|
||||
self.camera_class = get_camera_model(self.num_intrinsics_params)
|
||||
camera = self.camera_class(*self.intrinsics[camera_index].tolist())
|
||||
self.image_coords = nn.Parameter(camera.get_image_coords(), requires_grad=False)
|
||||
self.cameras = cameras
|
||||
self.image_coords = nn.Parameter(cameras.get_image_coords(), requires_grad=False)
|
||||
|
||||
def forward(self, ray_indices: TensorType["num_rays", 3]) -> RayBundle:
|
||||
"""Index into the cameras to generate the rays.
|
||||
@@ -58,12 +45,11 @@ class RayGenerator(nn.Module):
|
||||
c = ray_indices[:, 0] # camera indices
|
||||
y = ray_indices[:, 1] # row indices
|
||||
x = ray_indices[:, 2] # col indices
|
||||
intrinsics = self.intrinsics[c]
|
||||
camera_to_world = self.camera_to_world[c]
|
||||
coords = self.image_coords[y, x]
|
||||
|
||||
ray_bundle = self.camera_class.generate_rays(
|
||||
intrinsics=intrinsics, camera_to_world=camera_to_world, coords=coords
|
||||
ray_bundle = self.cameras.generate_rays(
|
||||
camera_indices=c,
|
||||
coords=coords,
|
||||
)
|
||||
ray_bundle.camera_indices = c[..., None] # ["num_rays",1]
|
||||
return ray_bundle
|
||||
Reference in new issue
Block a user