add an einsum_distloss implementation#2
Open
Spark001 wants to merge 3 commits intosunset1995:mainfrom
Open
Conversation
Author
|
Updates: Provide a python-interface implementation for distortion loss, no cuda kernels needed. def einsum_distloss(w, m, interval):
'''
Einsum realization of distortion loss.
There are B rays each with N sampled points.
w: Float tensor in shape [B,N]. Volume rendering weights of each point.
m: Float tensor in shape [N]. Midpoint distance to camera of each point.
interval: Scalar or float tensor in shape [B,N]. The query interval of each point.
Note:
The first term of distortion could be experssed as `(w @ mm @ w.T).diagonal()`, which
could be further accelerated by einsum function `torch.einsum('bq, qp, bp->b', w, mm, w)`
'''
mm = (m.unsqueeze(-1) - m.unsqueeze(-2)).abs() # [N,N]
loss = torch.einsum('bq, qp, bp->b', w, mm, w)
loss += (w*w*interval).sum(-1)/3.
return loss.mean() |
Author
|
|
@Spark001: in your example, you are assuming that |
Author
|
@bchretien Yes, you are right. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.