question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

LNCC loss instability for large kernel size

See original GitHub issue

Discussed in https://github.com/Project-MONAI/MONAI/discussions/3463

<div type='discussions-op-text'>

Originally posted by ebrahimebrahim December 9, 2021 I experienced some numerically unstable training while using LNCC loss to train a registration network. Exploding gradients, clipping them not helping, training loss increasing even with a low learning rate, etc.

This is in the context of synthetic data, where the images contained large homogeneous blobs, and so the variances used to compute LNCC were probably quite low.

I see that small variance has been a problem in the past and that it has been addressed. However, I seem to still have the issue when I set the kernel_size argument for LNCC loss to be large. Setting it back to a small value like 3 fixes the problem completely. Setting it to a large value (say, half the image size) leads to problems.

I think that giving a large kernel_size to LNCC is a natural thing to do, because NCC (normalized cross correlation, without the “local”) is the case of having kernel_size equal image size, if I’m understanding correctly.

Is there any reason to expect that large kernel size would worsen the instability problem? From the code, it’s not clear to me why the LNCC kernel size would matter. Thoughts, anyone?</div>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
wylicommented, Nov 4, 2022

thanks for the discussion here, it’s an issue handling the zero variance… I’ve included a patch in this PR to fix it https://github.com/Project-MONAI/MONAI/pull/5473.

@ebrahimebrahim I run your scripts and now the large kernels work fine. it’s also quite efficient…

Screenshot 2022-11-04 at 17 42 59 lncc

1reaction
Constantin-Jehncommented, Jun 14, 2022

I had similar problems for “big” kernel sizes.

I could overcome them by using the implementation from voxelmorph: https://github.com/voxelmorph/voxelmorph/blob/dev/voxelmorph/torch/losses.py

So maybe someone could compare to that code.

I would like to add that “overcoming” was too strongly stated. I also get into trouble with the sent Code, however at considerably higher learning rates and kernel sizes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

LNCC loss instability for large kernel size #3463 - GitHub
I experienced some numerically unstable training while using LNCC loss to train a registration network. Exploding gradients, clipping them not helping, ...
Read more >
Revisiting Large Kernel Design in CNNs - arXiv
Following the guidelines, we propose RepLKNet, a pure CNN architecture whose kernel size is as large as 31x31, in contrast to commonly used...
Read more >
Construction of Longitudinally Consistent 4D Infant ... - NCBI
LReg, which constrains the large deformations by penalizing the deviations of estimated deformation fields, is based on a Correntropy loss (Closs) [30], a...
Read more >
Networks for Joint Affine and Non-parametric Image Registration ...
An inverse consistency loss both for the affine and the vSVF registration ... Here we generalize LNCC to a multi-kernel LNCC formulation (mk-LNCC)....
Read more >
Sylle Hoogeveen - TU Delft Repositories
LSTM - Long-Short Term Memory ... 2.3.1 Modelling blood flow in large arteries . ... has a kernel size (in this case 3x3)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found