Skip to content

Conversation

@ericspod
Copy link
Member

@ericspod ericspod commented Feb 25, 2021

Fixes #1592.

Description

Fixes most of the loss functions to be compatible with Torchscript. Omits LocalNormalizedCrossCorrelationLoss, GlobalMutualInformationLoss, and BendingEnergyLoss as some significant code changes may be necessary. The changes made mostly are about dealing with Torchscript limitations regarding generator expressions or acceptable argument types. Union for example isn't compatible since statically-typed compiled code is targeted by Torchscript and this cannot handle this sort of polymorphism (I think).

One outstanding issue is that Enum classes are not compatible with Torchscript in Pytorch<1.7. The tests for Dice, Tversky, and others is only run for versions 1.7 and up.

Status

Ready

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 --codeformat --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

…rchscript

Signed-off-by: Eric Kerfoot <eric.kerfoot@kcl.ac.uk>
Signed-off-by: Eric Kerfoot <eric.kerfoot@kcl.ac.uk>
Signed-off-by: Eric Kerfoot <eric.kerfoot@kcl.ac.uk>
@ericspod
Copy link
Member Author

/black

monai-bot and others added 4 commits February 25, 2021 13:29
Signed-off-by: monai-bot <monai.miccai2019@gmail.com>
Signed-off-by: Eric Kerfoot <eric.kerfoot@kcl.ac.uk>
Signed-off-by: Eric Kerfoot <eric.kerfoot@kcl.ac.uk>
@ericspod ericspod marked this pull request as ready for review February 25, 2021 17:01
@ericspod ericspod requested review from Nic-Ma, rijobro, wyli and yiheng-wang-nv and removed request for yiheng-wang-nv February 25, 2021 17:02
Copy link
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

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

thanks, these are non-breaking enhancements for torchscript support

@wyli wyli merged commit 3c45f18 into Project-MONAI:master Feb 25, 2021
@ericspod ericspod deleted the loss_script_fixes branch February 25, 2021 18:23
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.

DiceLoss can't support TorchScript

3 participants