Skip to content

Commit

Permalink
remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
botaoye committed Nov 1, 2024
1 parent f74b8e0 commit 8d07ac0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 62 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
```
47 changes: 0 additions & 47 deletions src/model/decoder/cuda_splatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
17 changes: 3 additions & 14 deletions src/model/encoder/encoder_noposplat_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -167,22 +162,16 @@ 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)
for i in range(1, v):
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)
Expand Down

0 comments on commit 8d07ac0

Please sign in to comment.