From 8d07ac0a772b4114af1e00077c56dc27e3e3280c Mon Sep 17 00:00:00 2001 From: Botao Ye Date: Fri, 1 Nov 2024 14:53:40 +0100 Subject: [PATCH] remove redundant code --- README.md | 2 +- src/model/decoder/cuda_splatting.py | 47 -------------------- src/model/encoder/encoder_noposplat_multi.py | 17 ++----- 3 files changed, 4 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index db69271..4ba4fef 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,7 @@ We thank the kindly help of [David Charatan](https://davidcharatan.com/#/) for p @article{ye2024noposplat, title = {No Pose, No Problem: Surprisingly Simple 3D Gaussian Splats from Sparse Unposed Images}, author = {Ye, Botao and Liu, Sifei and Xu, Haofei and Xueting, Li and Pollefeys, Marc and Yang, Ming-Hsuan and Songyou, Peng}, - journal = {arXiv preprint arXiv:xxxx.xxxx}, + journal = {arXiv preprint arXiv:2410.24207}, year = {2024} } ``` \ No newline at end of file diff --git a/src/model/decoder/cuda_splatting.py b/src/model/decoder/cuda_splatting.py index 2ec9a2c..b64f182 100644 --- a/src/model/decoder/cuda_splatting.py +++ b/src/model/decoder/cuda_splatting.py @@ -11,7 +11,6 @@ from torch import Tensor from ...geometry.projection import get_fov, homogenize_points -from ..encoder.epipolar.conversions import depth_to_relative_disparity def get_projection_matrix( @@ -229,49 +228,3 @@ def render_cuda_orthographic( DepthRenderingMode = Literal["depth", "disparity", "relative_disparity", "log"] - - -def render_depth_cuda( - extrinsics: Float[Tensor, "batch 4 4"], - intrinsics: Float[Tensor, "batch 3 3"], - near: Float[Tensor, " batch"], - far: Float[Tensor, " batch"], - image_shape: tuple[int, int], - gaussian_means: Float[Tensor, "batch gaussian 3"], - gaussian_covariances: Float[Tensor, "batch gaussian 3 3"], - gaussian_opacities: Float[Tensor, "batch gaussian"], - scale_invariant: bool = True, - mode: DepthRenderingMode = "depth", -) -> Float[Tensor, "batch height width"]: - # Specify colors according to Gaussian depths. - camera_space_gaussians = einsum( - extrinsics.inverse(), homogenize_points(gaussian_means), "b i j, b g j -> b g i" - ) - fake_color = camera_space_gaussians[..., 2] - - if mode == "disparity": - fake_color = 1 / fake_color - elif mode == "relative_disparity": - fake_color = depth_to_relative_disparity( - fake_color, near[:, None], far[:, None] - ) - elif mode == "log": - fake_color = fake_color.minimum(near[:, None]).maximum(far[:, None]).log() - - # Render using depth as color. - b, _ = fake_color.shape - result = render_cuda( - extrinsics, - intrinsics, - near, - far, - image_shape, - torch.zeros((b, 3), dtype=fake_color.dtype, device=fake_color.device), - gaussian_means, - gaussian_covariances, - repeat(fake_color, "b g -> b g c ()", c=3), - gaussian_opacities, - scale_invariant=scale_invariant, - use_sh=False, - ) - return result.mean(dim=1) diff --git a/src/model/encoder/encoder_noposplat_multi.py b/src/model/encoder/encoder_noposplat_multi.py index f35a0bb..fab12ab 100644 --- a/src/model/encoder/encoder_noposplat_multi.py +++ b/src/model/encoder/encoder_noposplat_multi.py @@ -19,8 +19,6 @@ from .backbone import Backbone, BackboneCfg, get_backbone from .common.gaussian_adapter import GaussianAdapter, GaussianAdapterCfg, UnifiedGaussianAdapter from .encoder import Encoder -from .epipolar.depth_predictor_monocular import DepthPredictorMonocular -from .epipolar.epipolar_transformer import EpipolarTransformer, EpipolarTransformerCfg from .visualization.encoder_visualizer_epipolar_cfg import EncoderVisualizerEpipolarCfg @@ -63,10 +61,7 @@ def rearrange_head(feat, patch_size, H, W): class EncoderNoPoSplatMulti(Encoder[EncoderNoPoSplatCfg]): backbone: nn.Module - depth_predictor: DepthPredictorMonocular - to_gaussians: nn.Sequential gaussian_adapter: GaussianAdapter - high_resolution_skip: nn.Sequential def __init__(self, cfg: EncoderNoPoSplatCfg) -> None: super().__init__(cfg) @@ -167,15 +162,7 @@ def forward( all_mean_res.append(res2) # for the 3DGS heads - if self.gs_params_head_type == 'linear': - GS_res1 = rearrange_head(self.gaussian_param_head(dec1[-1]), self.patch_size, h, w) - GS_res2 = rearrange_head(self.gaussian_param_head2(dec2[-1]), self.patch_size, h, w) - elif self.gs_params_head_type == 'dpt': - GS_res1 = self.gaussian_param_head([tok.float() for tok in dec1], shape1[0].cpu().tolist()) - GS_res1 = rearrange(GS_res1, "b d h w -> b (h w) d") - GS_res2 = self.gaussian_param_head2([tok.float() for tok in dec2], shape2[0].cpu().tolist()) - GS_res2 = rearrange(GS_res2, "b d h w -> b (h w) d") - elif self.gs_params_head_type == 'dpt_gs': + if self.gs_params_head_type == 'dpt_gs': GS_res1 = self.gaussian_param_head([tok[:, 0].float() for tok in dec_feat], all_mean_res[0]['pts3d'].permute(0, 3, 1, 2), images[:, 0, :3], shape[0, 0].cpu().tolist()) GS_res1 = rearrange(GS_res1, "b d h w -> b (h w) d") all_other_params.append(GS_res1) @@ -183,6 +170,8 @@ def forward( GS_res2 = self.gaussian_param_head2([tok[:, i].float() for tok in dec_feat], all_mean_res[i]['pts3d'].permute(0, 3, 1, 2), images[:, i, :3], shape[0, i].cpu().tolist()) GS_res2 = rearrange(GS_res2, "b d h w -> b (h w) d") all_other_params.append(GS_res2) + else: + raise NotImplementedError(f"unexpected {self.gs_params_head_type=}") pts_all = [all_mean_res_i['pts3d'] for all_mean_res_i in all_mean_res] pts_all = torch.stack(pts_all, dim=1)