Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Signed-off-by: Eric Kerfoot eric.kerfoot@kcl.ac.uk
Fixes #1160.
Description
This introduces a number of changes to networks and their components to be compatible with Torchscript. Every network is being tested, except
DynUNet, by converting it to a Torchscript script then back to a network before running a forward pass of synthetic data through it. This should ensure that a saved network represents a valid Pytorch object which can be reloaded and used without needing the original codebase. Going forward new networks need to check for Torchscript compatibility by including the sort of tests that have been added here, avoid usingsuperin their definition, avoiding inheritance definitions that requiresuper, and iterating over indices (eg.for i in range(t.shape[0])) in favour of usingenumerateandzipwhen traversing lists.The
DynUNetis not currently compatible because it relies on iteration through lists of modules or the ListModule class. These are not currently compatible with Torchscript so a different architecture for this class is needed. It's possible to inherit from the existing UNet which is structured differently for this reason, however Torchscript does also have issues with thesuperkeyword so a little more design thought is needed to account for the variation in theDynUNet.forwardmethod which would need to usesuperin such a case.Changes were made to the squeeze and excitation classes to also account for Torchscript's lack of support for
forward. Other things not supported and removed include thereversefunction andTensor.ndimensionmethod.The return types for some methods of
UNetwere also made more general to accommodate future subtypes which might override these methods to return different subtypes ofnn.Module. Other classes might need to be modified in a similar way in the future for the same reason.Status
Ready
Types of changes
./runtests.sh --codeformat --coverage../runtests.sh --quick.make htmlcommand in thedocs/folder.