Fix #3064 and some minor changes (#3121)

This commit is contained in:
J.Y authored and GitHub committed 2024-05-01 12:43:41 -07:00
1 parent e232227e31
commit 3c4c3ae07e
3 files changed
+18 -16

No files matched your search

@@ -157,9 +157,13 @@ class FullImageDatamanager(DataManager, Generic[TDataset]):
def undistort_idx(idx: int) -> Dict[str, torch.Tensor]:
data = dataset.get_data(idx, image_type=self.config.cache_images_type)
camera = dataset.cameras[idx].reshape(())
K = camera.get_intrinsics_matrices().numpy()
assert data["image"].shape[1] == camera.width.item() and data["image"].shape[0] == camera.height.item(), (
f'The size of image ({data["image"].shape[1]}, {data["image"].shape[0]}) loaded '
f'does not match the camera parameters ({camera.width.item(), camera.height.item()})'
)
if camera.distortion_params is None:
return data
K = camera.get_intrinsics_matrices().numpy()
distortion_params = camera.distortion_params.numpy()
image = data["image"].numpy()
+10 -14
View File
@@ -649,6 +649,13 @@ class SplatfactoModel(Model):
return resize_image(image, d)
return image
@staticmethod
def get_empty_outputs(camera, background):
rgb = background.repeat(int(camera.height.item()), int(camera.width.item()), 1)
depth = background.new_ones(*rgb.shape[:2], 1) * 10
accumulation = background.new_zeros(*rgb.shape[:2], 1)
return {"rgb": rgb, "depth": depth, "accumulation": accumulation, "background": background}
def get_outputs(self, camera: Cameras) -> Dict[str, Union[torch.Tensor, List]]:
"""Takes in a Ray Bundle and returns a dictionary of outputs.
@@ -687,10 +694,7 @@ class SplatfactoModel(Model):
if self.crop_box is not None and not self.training:
crop_ids = self.crop_box.within(self.means).squeeze()
if crop_ids.sum() == 0:
rgb = background.repeat(int(camera.height.item()), int(camera.width.item()), 1)
depth = background.new_ones(*rgb.shape[:2], 1) * 10
accumulation = background.new_zeros(*rgb.shape[:2], 1)
return {"rgb": rgb, "depth": depth, "accumulation": accumulation, "background": background}
return self.get_empty_outputs(camera, background)
else:
crop_ids = None
camera_downscale = self._get_downscale_factor()
@@ -750,11 +754,7 @@ class SplatfactoModel(Model):
camera.rescale_output_resolution(camera_downscale)
if (self.radii).sum() == 0:
rgb = background.repeat(H, W, 1)
depth = background.new_ones(*rgb.shape[:2], 1) * 10
accumulation = background.new_zeros(*rgb.shape[:2], 1)
return {"rgb": rgb, "depth": depth, "accumulation": accumulation, "background": background}
return self.get_empty_outputs(camera, background)
if self.config.sh_degree > 0:
viewdirs = means_crop.detach() - optimized_camera_to_world.detach()[:3, 3] # (N, 3)
@@ -925,11 +925,7 @@ class SplatfactoModel(Model):
A dictionary of metrics.
"""
gt_rgb = self.composite_with_background(self.get_gt_img(batch["image"]), outputs["background"])
d = self._get_downscale_factor()
if d > 1:
predicted_rgb = resize_image(outputs["rgb"], d)
else:
predicted_rgb = outputs["rgb"]
predicted_rgb = outputs["rgb"]
combined_rgb = torch.cat([gt_rgb, predicted_rgb], dim=1)
+3 -1
View File
@@ -179,7 +179,9 @@ class RenderStateMachine(threading.Thread):
desired_depth_pixels = {"low_move": 128, "low_static": 128, "high": 512}[self.state] ** 2
current_depth_pixels = outputs["depth"].shape[0] * outputs["depth"].shape[1]
scale = min(desired_depth_pixels / current_depth_pixels, 1.0)
# from the panel of ns-viewer, it is possible for user to enter zero resolution
scale = min(desired_depth_pixels / max(1, current_depth_pixels), 1.0)
outputs["gl_z_buf_depth"] = F.interpolate(
outputs["depth"].squeeze(dim=-1)[None, None, ...],