Skip to content

Add MONAI loss configuration classes - #914

Open
txmed82 wants to merge 6 commits into
aramis-lab:devfrom
txmed82:agent/add-monai-loss-configs
Open

Add MONAI loss configuration classes#914
txmed82 wants to merge 6 commits into
aramis-lab:devfrom
txmed82:agent/add-monai-loss-configs

Conversation

@txmed82

@txmed82 txmed82 commented Jul 17, 2026

Copy link
Copy Markdown

Closes #907

Summary

  • add typed, serializable configs for Dice, DiceCE, DiceFocal, generalized Dice, generalized Dice-Focal, Focal, and Tversky MONAI losses
  • register the configs with the existing loss enum and factory while preserving MONAI 1.5.0 defaults
  • validate activation exclusivity and bounded or non-negative parameters, with support for scalar and list class weights
  • document the new public configuration classes

Why

Raw MONAI losses already work in ClinicaDL, but their constructor parameters are not preserved in model configuration JSON. These config classes make common segmentation-loss choices reproducible and reloadable.

Validation

  • pytest tests/unittests/losses -q — 78 passed
  • pytest tests/unittests/models/test_factory.py tests/unittests/models/test_supervised.py tests/unittests/models/test_reconstruction.py tests/unittests/metrics/test_loss.py -q — 5 passed
  • affected pre-commit hooks — passed
  • make -C docs html — succeeded with 7 pre-existing warnings
  • a broader CPU unit run reached 959 passed, 1 skipped, and 12 deselected before being stopped during slow training tests; two environment-only failures caused by missing pip were rerun after installing it, and both passed

@thibaultdvx

Copy link
Copy Markdown
Collaborator

Hey @txmed82, thanks for the PR! I will have a look at it tomorrow

@thibaultdvx thibaultdvx added the enhancement Enhancement of an existing feature label Jul 20, 2026
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.21260% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.00%. Comparing base (8d8fa9f) to head (46414a5).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #914      +/-   ##
==========================================
+ Coverage   97.96%   98.00%   +0.04%     
==========================================
  Files         216      217       +1     
  Lines       10728    10850     +122     
  Branches     1056     1060       +4     
==========================================
+ Hits        10510    10634     +124     
+ Misses        119      118       -1     
+ Partials       99       98       -1     
Flag Coverage Δ
functional 78.51% <88.18%> (+0.12%) ⬆️
gpu-functional 78.62% <88.18%> (+0.12%) ⬆️
gpu-unittests 62.63% <89.76%> (+0.32%) ⬆️
multi-gpu-unittests 56.83% <89.76%> (+0.38%) ⬆️
unittests 97.52% <99.21%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thibaultdvx
thibaultdvx self-requested a review July 21, 2026 11:26
@thibaultdvx
thibaultdvx marked this pull request as ready for review July 21, 2026 13:47

@thibaultdvx thibaultdvx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! Thanks for the great work :)

FocalLossConfig(gamma=3, alpha=0.25, use_softmax=True),
],
)
def test_monai_loss_non_default_round_trip(config):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you add a docstring to explain why this test is necessary?

Comment thread CITATION.cff
Comment on lines +40 to +43
- family-names: Son
given-names: Colin
website: https://github.com/txmed82
orcid: https://orcid.org/0000-0002-1782-0537

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey @txmed82, could you please make sure that this information is correct. Feel free to add your email or affiliation‎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Config class for loss functions from MONAI

2 participants