mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-02 05:48:57 +08:00
fix bilagrid
This commit is contained in:
1 parent
7c7b859ab0
commit
c325ce41cf
2 files changed
+14
-6
No files matched your search
@@ -408,6 +408,9 @@ class FullImageDatamanager(DataManager, Generic[TDataset]):
|
|||||||
) # Note that this must happen before indexing cameras, as it can modify the cameras in the dataset during undistortion
|
) # Note that this must happen before indexing cameras, as it can modify the cameras in the dataset during undistortion
|
||||||
cameras = nerfstudio_collate([self.train_dataset.cameras[i : i + 1].to(self.device) for i in camera_indices])
|
cameras = nerfstudio_collate([self.train_dataset.cameras[i : i + 1].to(self.device) for i in camera_indices])
|
||||||
|
|
||||||
|
if cameras.metadata is None:
|
||||||
|
cameras.metadata = {}
|
||||||
|
cameras.metadata["cam_idx"] = torch.tensor(camera_indices, device=self.device, dtype=torch.long)
|
||||||
return cameras, data
|
return cameras, data
|
||||||
|
|
||||||
def next_eval(self, step: int) -> Tuple[Cameras, Dict]:
|
def next_eval(self, step: int) -> Tuple[Cameras, Dict]:
|
||||||
|
|||||||
@@ -473,7 +473,11 @@ class SplatfactoModel(Model):
|
|||||||
raise ValueError(f"Unknown background color {self.config.background_color}")
|
raise ValueError(f"Unknown background color {self.config.background_color}")
|
||||||
return background
|
return background
|
||||||
|
|
||||||
def _apply_bilateral_grid(self, rgb: torch.Tensor, cam_idx: int, H: int, W: int) -> torch.Tensor:
|
def _apply_bilateral_grid(self, rgb: torch.Tensor, cam_idxs: torch.Tensor, H: int, W: int) -> torch.Tensor:
|
||||||
|
"""
|
||||||
|
rgb: [B, H, W, 3]
|
||||||
|
cam_idxs: [B]
|
||||||
|
"""
|
||||||
# make xy grid
|
# make xy grid
|
||||||
grid_y, grid_x = torch.meshgrid(
|
grid_y, grid_x = torch.meshgrid(
|
||||||
torch.linspace(0, 1.0, H, device=self.device),
|
torch.linspace(0, 1.0, H, device=self.device),
|
||||||
@@ -481,14 +485,13 @@ class SplatfactoModel(Model):
|
|||||||
indexing="ij",
|
indexing="ij",
|
||||||
)
|
)
|
||||||
grid_xy = torch.stack([grid_x, grid_y], dim=-1).unsqueeze(0)
|
grid_xy = torch.stack([grid_x, grid_y], dim=-1).unsqueeze(0)
|
||||||
|
|
||||||
out = slice(
|
out = slice(
|
||||||
bil_grids=self.bil_grids,
|
bil_grids=self.bil_grids,
|
||||||
rgb=rgb,
|
rgb=rgb, # Process the entire batch in parallel
|
||||||
xy=grid_xy,
|
xy=grid_xy.expand(rgb.shape[0], -1, -1, -1), # Expand grid_xy to match batch size
|
||||||
grid_idx=torch.tensor(cam_idx, device=self.device, dtype=torch.long),
|
grid_idx=cam_idxs.unsqueeze(-1),
|
||||||
)
|
)
|
||||||
return out["rgb"]
|
return out["rgb"] # Return the processed RGB directly
|
||||||
|
|
||||||
def get_outputs(self, cameras: Cameras) -> Dict[str, Union[torch.Tensor, List]]:
|
def get_outputs(self, cameras: Cameras) -> Dict[str, Union[torch.Tensor, List]]:
|
||||||
"""Takes in cameras and returns a dictionary of outputs.
|
"""Takes in cameras and returns a dictionary of outputs.
|
||||||
@@ -598,6 +601,8 @@ class SplatfactoModel(Model):
|
|||||||
if self.config.use_bilateral_grid and self.training:
|
if self.config.use_bilateral_grid and self.training:
|
||||||
if cameras.metadata is not None and "cam_idx" in cameras.metadata:
|
if cameras.metadata is not None and "cam_idx" in cameras.metadata:
|
||||||
rgb = self._apply_bilateral_grid(rgb, cameras.metadata["cam_idx"], H, W)
|
rgb = self._apply_bilateral_grid(rgb, cameras.metadata["cam_idx"], H, W)
|
||||||
|
else:
|
||||||
|
raise ValueError("Camera index not found in metadata, bilateral grid cannot be applied.")
|
||||||
|
|
||||||
if render_mode == "RGB+ED":
|
if render_mode == "RGB+ED":
|
||||||
depth_im = render[:, ..., 3:4]
|
depth_im = render[:, ..., 3:4]
|
||||||
|
|||||||
Reference in new issue
Block a user