Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2DGS #208

Merged
merged 118 commits into from
Sep 12, 2024
Merged

2DGS #208

merged 118 commits into from
Sep 12, 2024

Conversation

FantasticOven2
Copy link
Contributor

@FantasticOven2 FantasticOven2 commented Jun 8, 2024

This is an attempt to integrate 2DGS https://surfsplatting.github.io/ into gsplat. You can run simple 2D traning example with:
2D verification examples:
python examples/2d_example.py --model-type {3dgs, 2dgs}
Image fitting:
python examples/image_fitting.py --model-type {3dgs, 2dgs}

3D scene reconstruction:
python examples/simple_trained_2dgs.py --data-dir ...

traj_29999.1.1.mp4

Evaluations (Average over 7 scenes in Mipnerf-360 dataset)
w/o regularization

Scene PSNR SSIM LPIPS Memory (GB) Train Time (min:sec) Num GS
gsplat 28.76 0.8669 0.1450 3.70 15:44 1.90M
gsplat (packed) 28.74 0.8617 0.1448 3.48 15:25 1.89M
inria 28.73 0.8601 0.1480 3.73 22:16 1.93M

w/ normal consistency regularization

Scene PSNR SSIM LPIPS Memory (GB) Train Time (min:sec) Num GS
gsplat 27.85 0.8436 0.1853 3.78 16:48 1.96M
inria 28.06 0.8492 0.1694 3.66 22:18 1.91M

w/ normal consistency, distortion regularization

Scene PSNR SSIM LPIPS Memory (GB) Train Time (min:sec) Num GS
gsplat 27.80 0.8422 0.1866 3.76 16:44 1.96M
inria 28.05 0.8489 0.1697 3.61 22:06 1.88M

@FantasticOven2 FantasticOven2 changed the title 2DGS Old Version 2DGS Jun 8, 2024
@FantasticOven2 FantasticOven2 marked this pull request as draft June 8, 2024 07:05
@FantasticOven2 FantasticOven2 reopened this Jun 8, 2024
Copy link
Collaborator

@vye16 vye16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a wonderful start! I think it would be great to have similar numerical testing the same way that we have for the 3dgs, but we can coordinate this.

I'm inclined to separate the two into separate functions and interfaces, what are your thoughts @liruilong940607? There is also a lot of repeated code but that's not a big problem for now, we can figure out if/how we can share between 2dgs and 3dgs later once.

// moving the channel padding from python to C side.
switch (channels) {
case 1:
rasterize_to_pixels_fwd_kernel<1><<<blocks, threads, 0, stream>>>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rasterize_to_pixels_fwd_2dgs_kernel right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops! Good catch!

@@ -300,6 +293,10 @@ def rasterize_gaussians(
block_width: int,
background: Optional[Float[Tensor, "channels"]] = None,
return_alpha: Optional[bool] = False,
model_type: Literal["3dgs", "2dgs"] = "3dgs",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to just make a separate function for 2dgs, but @liruilong940607 what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that would be my preference as well. seems like 2D GS projection and 3D GS have different argument list, though some are shared, it would be a bit confusing to squeeze all arguments into the same function.

@@ -548,6 +774,7 @@ def project_gaussians(
img_width: int,
block_width: int,
clip_thresh: float = 0.01,
model_type: Literal["3dgs", "2dgs"] = "3dgs"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here again, I feel like it'd be better to have separate functions

examples/image_fitting.py Show resolved Hide resolved
@liruilong940607
Copy link
Collaborator

liruilong940607 commented Jun 10, 2024

This is a wonderful start! I think it would be great to have similar numerical testing the same way that we have for the 3dgs, but we can coordinate this.

I'm inclined to separate the two into separate functions and interfaces, what are your thoughts @liruilong940607? There is also a lot of repeated code but that's not a big problem for now, we can figure out if/how we can share between 2dgs and 3dgs later once.

Yes totally agree. I definitely recommend start with developing as separate functions (or even separate files). This would make the development so much easier and faster without the need of considering compatibility and it won't interrupting what's already in there.

I imagine some helper functions might be able to get reused, like on the python side, there is sorting related functions, and maybe also rasterization? The projection is definitely different between 2D and 3D GS so would be nice to have different interfaces.

Merging is kinda like a cleanup, which we can certainly do it later.

glm::mat3 RS_camera = R * RS;
glm::mat3 WH = glm::mat3(RS_camera[0], RS_camera[1], mean_c);

glm::mat3 inverse_intrinsic = glm::mat3(
Copy link
Collaborator

@vye16 vye16 Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, the ellipse aabb in the original paper uses the projection matrix which transforms into clipping space, can we do this and directly take the same computation for ellipse aabb? @FantasticOven2 @liruilong940607 am I misunderstanding this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using ray-splat intersection to compute AABB is more accurate than using the perspective transformation for ellipse aabb in the original paper as mentioned here; the author also worked out the math here

@gchhablani
Copy link

I am highly interested in having this handy.
Just curious, will this also be able to support things like Gaussian Surfels (which is pretty much the same as 2DGS), but interesting losses: https://github.com/turandai/gaussian_surfels

@FantasticOven2
Copy link
Contributor Author

Forward pass works on simple 2D experiments for v1.0
3dgs
2dgs

@FantasticOven2
Copy link
Contributor Author

FantasticOven2 commented Jun 15, 2024

Slant views
3dgs_slant_view
(3DGS)
2dgs_slant_view
(2DGS)

@hardikdava
Copy link
Contributor

@FantasticOven2 I have tried to install latest version and it seems working after decreasing MAX_JOBS in setup.py. If I set to MAX_JOBS=10 then the system is crashing for me.

c.c. @liruilong940607

@liruilong940607
Copy link
Collaborator

Oh I think the renders folder are accidentally added into the commit, because of the removal (by me) of the renders in .gitignore.

Could you remove that from this PR? Feels like maybe the results folder is enough for dumping things locally.

@FantasticOven2
Copy link
Contributor Author

Oh I think the renders folder are accidentally added into the commit, because of the removal (by me) of the renders in .gitignore.

Could you remove that from this PR? Feels like maybe the results folder is enough for dumping things locally.

Done!

@liruilong940607
Copy link
Collaborator

formatting as one last thing!! Thanks!

@FantasticOven2
Copy link
Contributor Author

formatting as one last thing!! Thanks!

Done!

@liruilong940607
Copy link
Collaborator

Format check is still failing. Could you run?

pip install black==22.3.0
black . gsplat/ tests/ examples/ profiling/

Also, the renders folder are submitted to this PR again ... We should probably change the path of this to results in the 2d image fitting script

@FantasticOven2
Copy link
Contributor Author

Format check is still failing. Could you run?

pip install black==22.3.0
black . gsplat/ tests/ examples/ profiling/

Also, the renders folder are submitted to this PR again ... We should probably change the path of this to results in the 2d image fitting script

the format is due to the black version mismatch; for the renders folder, do you mean examples/renders? I removed it and also change to "results" in image_fitting.py

Copy link
Collaborator

@liruilong940607 liruilong940607 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the long going efforts!

@liruilong940607 liruilong940607 merged commit 2d6a967 into nerfstudio-project:main Sep 12, 2024
2 checks passed
@Master-cai
Copy link
Contributor

Thanks for the hard work! I want to ask can we replace the 3dgs to the 2dgs by simply replacing the rasterization() to rasterization_2dgs() for rendering?

btw, is there a bug or typo?

render_colors, render_alphas = renders

It seems that no vars named renders in rasterize_splats().

Thanks!

cc @liruilong940607 @FantasticOven2

@aW4KeNiNG
Copy link

Thanks for the effort! Just a note, there is a missing option added in simple_trainer recently: "normalize_world_space"

@FantasticOven2
Copy link
Contributor Author

Thanks for the hard work! I want to ask can we replace the 3dgs to the 2dgs by simply replacing the rasterization() to rasterization_2dgs() for rendering?

btw, is there a bug or typo?

render_colors, render_alphas = renders

It seems that no vars named renders in rasterize_splats().
Thanks!

cc @liruilong940607 @FantasticOven2

Hey, thanks for pointing this out; yes this is a typo. I will update this later on. Since inria implementation is mainly used for benchmark, it shouldn't affect the gsplat implementation.

There are a few differences between rasterization and rasterization_2dgs, especially for the returned tensors. But it should be straightforward to switch from one to the other, and you can check the doc here for reference

@ozgunthirddimension
Copy link

Hello, Great work again. as I was running the code I have seen that when you set the absgrad to True it does not function and throw an error that there is no absgrad as a parameter for the densify. When I check the code it still only does it for means2d and I wonder if you plan to implement it also for the densift. Thanks. Have a nice day

@FantasticOven2
Copy link
Contributor Author

Hello, Great work again. as I was running the code I have seen that when you set the absgrad to True it does not function and throw an error that there is no absgrad as a parameter for the densify. When I check the code it still only does it for means2d and I wonder if you plan to implement it also for the densift. Thanks. Have a nice day

Hey!
Thanks for your interest and sorry for the late response. The current version of 2DGS doesn't support absgrad yet. I'm thinking about an updates for additional features such as (absgrad / anti-aliased) but not sure how long will it take; on the other hand you may try to implement absgrad yourself and it should very straightforward.

@sephyli
Copy link

sephyli commented Sep 27, 2024

Hi @FantasticOven2, thanks for the great work!
I noticed that in 2DGS, the gradient passed to the camera extrinsics is not available for the camera rotation. Is that normal?

@FantasticOven2
Copy link
Contributor Author

Hi @FantasticOven2, thanks for the great work! I noticed that in 2DGS, the gradient passed to the camera extrinsics is not available for the camera rotation. Is that normal?

Hey, Thanks for your interest! The current 2DGS doesn't support camera pose gradient yet.

We are working on additional features for 2DGS including camera pose gradient and will make an update in the next few month.

@bbartlett-nv
Copy link

Great work ! super interested in using for mesh extraction; any way to use the original "render.py" from the 2DGS repo from the pytorch checkpoint generated by this gsplat implementation? Or, plans to provide mesh extraction script here?

Thanks!

@FantasticOven2
Copy link
Contributor Author

Great work ! super interested in using for mesh extraction; any way to use the original "render.py" from the 2DGS repo from the pytorch checkpoint generated by this gsplat implementation? Or, plans to provide mesh extraction script here?

Thanks!

Hey! Thanks for your interest! Yes we do plan to add mesh extraction in the next one or two months. Meanwhile you can check Gaussian Opacity Field pull request as they have a draft mesh extraction

@bbartlett-nv
Copy link

great news! yep I have run that PR - works pretty well but need textures. looking forward to trying out your implementation.

@jk4011
Copy link

jk4011 commented Dec 17, 2024

Hi @FantasticOven2,
Will mesh extraction be implemented as you said?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.