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

[DRAFT] Mip-Splatting implementation #274

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

niujinshuchong
Copy link

@niujinshuchong niujinshuchong commented Jul 9, 2024

Implementation of Mip-Splatting. Tested on bicycle scenes and works OK.

Here is a comparison when trained with factor 4 and render with factor 1.
Screenshot from 2024-07-09 17-12-26

Screenshot from 2024-07-09 17-13-27
Left is from gsplat's default setting and right is from this PR.

Benchmark results on 7 scenes of Mip-NeRF 360 dataset:

PSNR SSIM LPIPS num_GS (M)
classic 28.989 0.871 0.136 3.23
antialiased 29.043 0.871 0.139 3.37
mip-splatting (this PR) 29.051 0.872 0.138 3.16
mip-splatting (this PR) + cuda implementation of compute_3D_smoothing_filter 29.017 0.873 0.139 3.14

Here is the benchmark results of training with factor 8 and render with factor 8, 4, 2, 1.

metric is PSNR, SSIM and LPIPS.

1x 2x 4x 8x avg. 1x 2x 4x 8x avg. 1x 2x 4x 8x avg.
classic 30.08 23.14 20.34 19.18 23.18 0.912 0.722 0.597 0.605 0.709 0.049 0.169 0.327 0.470 0.254
antialiased 29.77 24.69 22.39 21.65 24.63 0.904 0.736 0.605 0.588 0.708 0.056 0.174 0.304 0.438 0.243
mip-splatting (this PR) 30.29 26.84 26.07 26.14 27.33 0.916 0.799 0.748 0.776 0.810 0.050 0.192 0.309 0.428 0.245

Clean up later.

@liruilong940607
Copy link
Collaborator

Awesome @niujinshuchong !

I'm thinking if there is a way to elegantly message some of implementation into the gsplat library, e.g., into rasterization() function so that the downstream users (e.g., nerfstudio) can just import and use.

It doesn't have to be living in the rasterization() function if it does not fit there. We could also put some implementation in to like gsplat/mip.py, so that ppl can use it with:

from gsplat.mip import ...
# and do their thing

@liruilong940607
Copy link
Collaborator

I'll come back to it later with a closer look. Great job!

@niujinshuchong
Copy link
Author

@liruilong940607 Thanks for the suggestions. I added a cuda implementation of compute_3D_smoothing_filter and it can be imported from gsplat. The benchmark results (see top) are reasonable. For now, I create a new script simple_trainer_mip_splatting.py and it almost the same as simple_trainer.py, do you think we should merge them or make it separate? I also added a training script to use multiple gpus.

self.splats["filters"] = torch.nn.Parameter(filter_3D)

@torch.no_grad()
def compute_3D_smoothing_filter_torch(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would you mind move this into gsplat/cuda/_torch_impl.py and put up a test case under test/test_basic.py to protect the CUDA implementation compute_3D_smoothing_filter()?

@liruilong940607
Copy link
Collaborator

Thanks for the benchmarking! Really nice! Yeah from a quick going through of the training script, it seems to be very compatible with the original one so I would suggest we merge the two! Just need a flag in the config, e.g.(--mip_splatting?) and a couple if else in the code.

@@ -572,6 +572,34 @@ def rasterize_to_indices_in_range(
return out_gauss_ids, out_pixel_ids, out_camera_ids


def compute_3D_smoothing_filter(
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: maybe use 3d instead of 3D in the naming of these functions to align with the naming convention in gsplat?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice scripts!

  • Does GPUtil need to be installed via pip? If so we should put it into examples/requirements.txt.
  • If you are going to merge the simple_trainer_mip_splatting.py with simple_trainer.py then we can just replace the original benchmark script with this one, and enable an input flag to enable mip splatting. But merging the benchmark script means that we probably want the default benchmarking set to be the original 3DGS.

excluded_gpus = set([])

# classic
result_dir = "results/benchmark_stmt"
Copy link
Collaborator

Choose a reason for hiding this comment

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

what does stmt stands for? lol

Copy link
Collaborator

@maturk maturk Jul 18, 2024

Choose a reason for hiding this comment

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

I think Single-scale-Training-and-Multi-scale-Testing, the idea being you train with a fixed resolution (here a factor of 1/8 of the original image res) and test on various other resolutions (1x full res, 1/2, 1/4, 1/8).

Copy link
Collaborator

Choose a reason for hiding this comment

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

how hard would it be to merge this one with the other script? Ideally an list argument could be passed in to specify the rendering factors that the evaluation happens on

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 we could adapt the current benchmark.sh script into the .py style similar to the one proposed here, allowing for easier batch jobs on e.g. clusters and also streamlining the evaluation of the various new features of gsplat... I can look into it...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice script! Would love to have it! Maybe the name of this script could be something like "compare_results_mipnerf360" to be more readable? Actually maybe we could also get rid of the _mipnerf360 suffix until when another dataset is supported.

@@ -0,0 +1,45 @@
import json
Copy link
Collaborator

Choose a reason for hiding this comment

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

actually, another idea of managing these scripts is to have a mip_splatting folder under examples, in which you could have multiple scripts in there, without worrying about merging or conflicting with other scripts. I think this is a scalable way to manage the scripts when more things are supported in the future.

And you could also have a customized simple_trainer.py living in it, basically whatever you need to be customized. But this is less preferred because a customized simple_trainer.py means the mip-splatting feature would be disjoint with other future features for user to play with. So ideally we merge the trainer but could put the scripts into an isolated folder.

@jb-ye
Copy link
Collaborator

jb-ye commented Aug 15, 2024

What's the plan on merging this PR? I am particularly interested in this feature (esp. the 3D filter part).

@liruilong940607
Copy link
Collaborator

I think this PR is just about cleaning up, add doc strings and update webpage. It would be nice to finish it up.

Not sure if @niujinshuchong still has time for it. But I might be able to find some cycles in the next two weeks to help with finishing up this PR.

@jb-ye
Copy link
Collaborator

jb-ye commented Aug 15, 2024

I think this PR is just about cleaning up, add doc strings and update webpage. It would be nice to finish it up.

Not sure if @niujinshuchong still has time for it. But I might be able to find some cycles in the next two weeks to help with finishing up this PR.

Based on my experience with antialiased mode rasterization, I think the 3D filter should be always enabled for antialiased rasterization. Otherwise, a significant percentage of gaussians could become very thin and flat "2D" gaussians, which is often undesirable for modeling non-lambertian effect.

Also with 3D filter, one usually get less number of gaussians at the same quality post training.

@niujinshuchong
Copy link
Author

@liruilong940607 Yes, it just need to be clean up. I will find some time to continue. However, it would be great if you can help with it. Sorry for the late reply.

@jb-ye
Copy link
Collaborator

jb-ye commented Sep 5, 2024

@niujinshuchong We found one issue with the mip-splat implementation. See discussions: autonomousvision/mip-splatting#48

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.

4 participants