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

distortion loss impl. #244

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

distortion loss impl. #244

wants to merge 6 commits into from

Conversation

liruilong940607
Copy link
Collaborator

@liruilong940607 liruilong940607 commented Jun 29, 2024

Implement distortion loss for 3DGS from Mip-NeRF 360:
Screenshot 2024-06-29 at 10 32 53 AM

Note: Since the distortion loss is a per-pixel value, I implement it as a per-pixel map rendered from the rasterization() function, with the same resolution with the rendered image. This could be reduced into a scalar with a .mean() call on it for backward. Having the distortion loss as a map instead of a scalar could be useful for visualization and analysis purposes.

@maturk
Copy link
Collaborator

maturk commented Jul 1, 2024

@liruilong940607, I think there are some version issues with the Nerfacc library. I have Nerfacc Version: 0.5.3 installed (with pip install nerfacc) however, it seems that this is not compatible with the argument list in your test code. In particular I tracked down the commit and this has not been added to a new release, so pip installing nerfacc results in a version where there is no "indices" arguments to your implementations of inclusive/exclusive sums.

The error a user gets: TypeError: exclusive_sum() got an unexpected keyword argument 'indices'.

This can be fixed by installing from the git source but just a heads up...

)
torch.testing.assert_close(render_colors, _render_colors)
torch.testing.assert_close(render_alphas, _render_alphas)
torch.testing.assert_close(render_distloss, _render_distloss)

# backward
v_render_colors = torch.randn_like(render_colors)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not an issue, just a general question regarding the use of torch.autograd.grad(outputs * v_outputs ,inputs) in the gradient tests. Why do we scale outputs by these random v_outputs weights? Shouldn't torch.autograd.grad(outputs, inputs) suffice for gradient checking?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

torch.autograd.grad needs to take in a scalar in the first argument, which is essentially the loss. So here I'm testing against this formula:

dL_d(input) = dL_d(output) * d(output)/d(input)

Since we don't have the loss formula, I'll using a random tensor (v_output) to mimic dL_d(output), so the "loss" can be set to be loss = (output * v_output).sum().

Then the testing of dL_d(input) is:

torch.autograd.grad((outputs * v_outputs).sum() ,inputs)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Makes sense, thanks. Here is a small visual of the dist loss as a heatmap whilst training:
dist loss

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Very cool color theme! What theme are you using here?

The reason I haven't merge this PR is that I didn't find this distortion loss to be helpful on ANY of the scenes in MipNeRF 360, which is a bit frustrated and not expected.

Let me know if you find anything otherwise!

Copy link
Collaborator Author

@liruilong940607 liruilong940607 Jul 1, 2024

Choose a reason for hiding this comment

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

I'm guessing the reason that this distortion loss isn't useful might have something to do with the imperfect depth accumulation formulation that we are currently using. The depth formulation from Gaussian Opacity Fields or RaDe-GS seems to be more accurate, which might be a prerequisite for distortion loss to work.

Or, maybe its just that there aren't many floaters in these GS scenes anyway?

Copy link
Contributor

Choose a reason for hiding this comment

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

For those like me who were wondering what the awesome color scheme was, I think I tracked it down to cmr.voltage. https://cmasher.readthedocs.io/user/sequential/voltage.html

@FantasticOven2
Copy link
Contributor

I tried this distortion loss with 2DGS and below are the results:
(with distortion loss)
IMG_0672

(without distortion loss)
IMG_0673

Seems like the improvement is very subtle and focus on details; and this is also the case for the original 2DGS implementation; I will try the L2 version in the 2DGS paper next

@jefequien
Copy link
Contributor

jefequien commented Jul 8, 2024

@FantasticOven2 I think the speckle artifacts you have in your normal image are from overflowing uint8 in the visualization. You may need to clamp or normalize your normals.

@keunhong
Copy link
Contributor

Hi Ruilong, do you have any plans to merge this? I think it would be helpful in some more underconstrained settings.

@liruilong940607
Copy link
Collaborator Author

Hi Ruilong, do you have any plans to merge this? I think it would be helpful in some more underconstrained settings.

I haven't got a case where I find it useful and that's why I wasn't quite motivated to spend further efforts on merging it. But I guess it's true that all the cases I tried are well constrained.

I could try to find some cycles to merge this but no guarantee on the timeline!

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.

5 participants