Skip to content

Add stereo matching losses #6554

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

Merged
merged 15 commits into from
Sep 21, 2022

Conversation

TeodorPoncu
Copy link
Contributor

Some of the Stereo Matching criterions that can be added to a training loop for regularisation purposes. Contains two candidates for more generic usage: respectively SSIM and PSNR losses

Copy link
Contributor

@jdsgomes jdsgomes left a comment

Choose a reason for hiding this comment

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

Thanks for this, just left a couple of comments

@jdsgomes
Copy link
Contributor

Also as a general comment I suggest to only keep the losses that you need to replicate the models that we will provide weights for.

Copy link
Contributor

@YosuaMichael YosuaMichael left a comment

Choose a reason for hiding this comment

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

Hi @TeodorPoncu , thanks for the PR! In general, could you add reference (url to paper or other existing implementation) for the losses?
Also, I have few comments and questions.

if exclude_large:
# exclude invalid pixels and extremely large diplacements
flow_norm = torch.sum(flow_gt**2, dim=1).sqrt()
valid_flow_mask = valid_flow_mask & (flow_norm < max_flow)
Copy link
Contributor

Choose a reason for hiding this comment

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

In the transforms we have max_disparity and in here we have another max_flow and I think they are similar things.
Just wondering if we actually need both or just having max_flow here is enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

max_flow would be enough if we assume users to use our transforms. If that assumption is correct than that term is not needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at how sometimes we modify the valid_mask on the loss:

  1. We limit the norm of the flow in sequence loss with max_flow
  2. We limit each disparity axis to be some ratio of the image size in photometric loss

I think we may not need max_disparity in the transform. So if the dataset dont have any mask, we assume that the mask is all True during the transform. When we want to calculate the loss, then we actually modify this mask.

What do you think on this @TeodorPoncu ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, because some datasets have None returns for the disparity mask, whilst others don't. We need a transform that fills in that None with something. Even if max_disparity is not needed, we still have to impute somehow the None.

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently we allow max_disparity to be optional, and if it is None it will cause the problem you mention here. I think one possible solution is to let valid_flow_mask to be Optional as well here, and we treat None as if it is True everywhere. As indicated on previous comment, lets discuss on this particular topic first.

if exclude_large:
# exclude invalid pixels and extremely large diplacements
flow_norm = torch.sum(flow_gt**2, dim=1).sqrt()
valid_flow_mask = valid_flow_mask & (flow_norm < max_flow)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at how sometimes we modify the valid_mask on the loss:

  1. We limit the norm of the flow in sequence loss with max_flow
  2. We limit each disparity axis to be some ratio of the image size in photometric loss

I think we may not need max_disparity in the transform. So if the dataset dont have any mask, we assume that the mask is all True during the transform. When we want to calculate the loss, then we actually modify this mask.

What do you think on this @TeodorPoncu ?

def _sequence_loss_fn(
flow_preds: List[Tensor],
flow_gt: Tensor,
valid_flow_mask: Tensor,
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to follow up on my comment on #6549.
We may want the valid_flow_mask to be Optional here. But lets discuss this first

Note: I notice we already make valid_mask to be optional in Photometric loss

if exclude_large:
# exclude invalid pixels and extremely large diplacements
flow_norm = torch.sum(flow_gt**2, dim=1).sqrt()
valid_flow_mask = valid_flow_mask & (flow_norm < max_flow)
Copy link
Contributor

Choose a reason for hiding this comment

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

Currently we allow max_disparity to be optional, and if it is None it will cause the problem you mention here. I think one possible solution is to let valid_flow_mask to be Optional as well here, and we treat None as if it is True everywhere. As indicated on previous comment, lets discuss on this particular topic first.

Copy link
Contributor

@YosuaMichael YosuaMichael left a comment

Choose a reason for hiding this comment

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

Hi @TeodorPoncu , overall looks good to me! Just have a question regarding register_buffer

Copy link
Contributor

@YosuaMichael YosuaMichael left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@jdsgomes jdsgomes 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!

@TeodorPoncu TeodorPoncu merged commit 2c1022e into pytorch:main Sep 21, 2022
facebook-github-bot pushed a commit that referenced this pull request Sep 23, 2022
Summary:
* Moved more losses into classes

* Added photometric loss

* quick fix for ssim loss return value

* added references

* replaced with unsqueeze

* renaming variables

* add ref to consistency loss

* made mask optional everywhere. generalised photometric displacement

* smoothness typo

* fixed flow channel selection bug

* aligned with training script

Reviewed By: NicolasHug

Differential Revision: D39765303

fbshipit-source-id: 59fb6a5e0248d126b15390f2af91c5fc6f121909

Co-authored-by: Joao Gomes <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants