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

7263 add diffusion loss #7272

Merged
merged 9 commits into from
Dec 5, 2023
Merged

Conversation

kvttt
Copy link
Contributor

@kvttt kvttt commented Nov 29, 2023

Fixes #7263.

Description

Add diffusion loss. I also made a demo notebook to provide some explanations and analyses of diffusion loss.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

@kvttt kvttt marked this pull request as ready for review November 30, 2023 02:44
Signed-off-by: kaibo <ktang@unc.edu>
@kvttt
Copy link
Contributor Author

kvttt commented Nov 30, 2023

Hi @ebrahimebrahim, you worked on implementing BendingEnergyLoss earlier and provided an awesome demo notebook. Could you take a look at my demo notebook attached in this PR? It would be great to have you confirm that my analysis of diffusion loss make sense! Thank you!

@ebrahimebrahim
Copy link
Contributor

Happy to take a look! I'll get back to you on this soon

@ebrahimebrahim
Copy link
Contributor

ebrahimebrahim commented Dec 1, 2023

I just had a look. I like your derivation of the scaling law for diffusion loss!
In your result

$$L(\hat{{\bf u}}) = \frac{1}{|D|} \sum_{{\bf x} \in D} \left( \lambda_x^{-1}\lambda \odot \frac{\partial}{\partial x} ({\bf u}({\bf x})) \right)^2 + \left( \lambda_y^{-1} \lambda \odot \frac{\partial}{\partial y} ({\bf u}({\bf x})) \right)^2 + \left( \lambda_z^{-1} \lambda \odot \frac{\partial}{\partial z} ({\bf u}({\bf x})) \right)^2$$

if you assume isotropic scaling $\lambda_x=\lambda_y=\lambda_z$ then there is cancellation and you've shown that $L(\hat{{\bf u}}) \approx L({{\bf u}}) $. That is, there's only a weird scale-dependent effect to worry about when you change your image resolution along different axes differently. The examples in the notebook always do isotropic changes of resolution. This explains why in your plot you see scale-invariance (the eventually-flat line) regardless of whether normalize=True or not:
image
To really see the benefit of your normalize=True, you'd want to change resolution differently on the x axis versus the y axis.

But yeah I think I agree with your derivation of the scaling law and I like your approach!

@KumoLiu
Copy link
Contributor

KumoLiu commented Dec 1, 2023

/build

monai/losses/deform.py Outdated Show resolved Hide resolved
monai/losses/deform.py Outdated Show resolved Hide resolved
Copy link
Member

@ericspod ericspod left a comment

Choose a reason for hiding this comment

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

Looks good, I had a few comments with minor changes.

@KumoLiu
Copy link
Contributor

KumoLiu commented Dec 5, 2023

/build

@KumoLiu KumoLiu enabled auto-merge (squash) December 5, 2023 07:56
@KumoLiu
Copy link
Contributor

KumoLiu commented Dec 5, 2023

Would be great to add the demo to the tutorial repo and mention it in the docstring.

@KumoLiu KumoLiu merged commit d5585c3 into Project-MONAI:dev Dec 5, 2023
28 checks passed
marksgraham pushed a commit to marksgraham/MONAI that referenced this pull request Jan 30, 2024
Fixes Project-MONAI#7263.

### Description

Add diffusion loss. I also made a [demo
notebook](https://github.com/kvttt/deep-atlas/blob/main/diffusion_loss_scale_test.ipynb)
to provide some explanations and analyses of diffusion loss.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [x] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [x] In-line docstrings updated.
- [x] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: kaibo <ktang@unc.edu>
Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: Mark Graham <markgraham539@gmail.com>
juampatronics pushed a commit to juampatronics/MONAI that referenced this pull request Mar 25, 2024
Fixes Project-MONAI#7263.

### Description

Add diffusion loss. I also made a [demo
notebook](https://github.com/kvttt/deep-atlas/blob/main/diffusion_loss_scale_test.ipynb)
to provide some explanations and analyses of diffusion loss.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [x] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [x] In-line docstrings updated.
- [x] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: kaibo <ktang@unc.edu>
Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: Juan Pablo de la Cruz Gutiérrez <juampatronics@gmail.com>
Yu0610 pushed a commit to Yu0610/MONAI that referenced this pull request Apr 11, 2024
Fixes Project-MONAI#7263.

### Description

Add diffusion loss. I also made a [demo
notebook](https://github.com/kvttt/deep-atlas/blob/main/diffusion_loss_scale_test.ipynb)
to provide some explanations and analyses of diffusion loss.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [x] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [x] In-line docstrings updated.
- [x] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: kaibo <ktang@unc.edu>
Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: Yu0610 <612410030@alum.ccu.edu.tw>
vgrau98 pushed a commit to vgrau98/MONAI that referenced this pull request Apr 28, 2024
Fixes Project-MONAI#7263.

### Description

Add diffusion loss. I also made a [demo
notebook](https://github.com/kvttt/deep-atlas/blob/main/diffusion_loss_scale_test.ipynb)
to provide some explanations and analyses of diffusion loss.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [x] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [x] In-line docstrings updated.
- [x] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: kaibo <ktang@unc.edu>
Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
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.

Add diffusion regularizer for image registration
4 participants