[WIP] 2220 Decollate batch into list of tensors after model forward#2244
Conversation
merge master
merge master
merge master
Signed-off-by: Nic Ma <nma@nvidia.com>
|
In this drat PR, I tried to enhance the Thanks in advance. |
|
It looks fine to me. Do we have a particular use case for this? |
Hi @ericspod , Thanks for your review. post_transforms = Compose([
Activations(keys="pred"),
CopyItemsd(keys="pred", times=1, names="inverted_pred"),
Inverted(keys="inverted_pred", nearest_interp=False),
AsDiscreted(keys=["pred", "inverted_pred"]),
SaveImaged(keys=["pred", "inverted_pred"]),
])Thanks. |
|
@rijobro mentioned abstracting the concept out rather than inserting it into every transform everywhere. Earlier we had discussed transforms representing diverging paths in the transform sequence, for example something like OneOf where one of the transforms passed to the object as an argument is randomly chosen to be applied. Perhaps a wrapping transform that takes a list of tensors as you want and applies each in the list to the sequence of transforms it was given then either returns the list or collates the list. This would look like: post_transforms = Compose([
ApplyToSeqd(keys="pred", collate=False, [
Activations(keys="pred"),
CopyItemsd(keys="pred", times=1, names="inverted_pred"),
Inverted(keys="inverted_pred", nearest_interp=False),
AsDiscreted(keys=["pred", "inverted_pred"]),
SaveImaged(keys=["pred", "inverted_pred"]),
]) # output is dictionary with lists of tensors for values
]) |
|
So in summary, now we have 4 draft ideas to solve this problem:
Thanks. |
|
Good summary, let's discuss tomorrow. |
|
Thanks for this great online discussion. Thanks. |
thanks, if needed please create a branch in the codebase dedicated to this feature, it'll make it easier to manage the release of this feature |
Signed-off-by: Nic Ma <nma@nvidia.com>
|
Hi @wyli , Thanks for your suggestions. Thanks. |
Signed-off-by: Nic Ma <nma@nvidia.com>
|
I already updated all the necessary post / IO / utility transforms to be Thanks. |
thanks, I think we'll need full integration tests before merging this feature... these pre-merge tests won't be reliable enough for this PR. |
|
Hi @wyli , I will trigger integration tests when all the things are ready. Thanks |
Signed-off-by: Nic Ma <nma@nvidia.com>
|
I am adjusting the metrics interface, after decollating, there are several options:
I prefer to unify the metrics API to below signature, which was discussed in PR #565: class Metric:
def update(self, y_pred: Union[torch.Tensor, Sequence[torch.Tensor]], y: Union[torch.Tensor, Sequence[torch.Tensor]]):
# call for a decollated batch data usually when iteration completed
# compatible with `batch-first tensor` and `list of channnel-first tensor`
for pred_, y_ in zip(y_pred, y):
self._add_sample(pred_, y_)
def _add_sample(self, y_pred: torch.Tensor, y: torch.Tensor):
# execute logic for 1 sample of the batch
pass
def compute(self):
# call for final computation usually when epoch completed
passWhat do you guys think? Thanks. |
Signed-off-by: Nic Ma <nma@nvidia.com>
merge master
Signed-off-by: Nic Ma <nma@nvidia.com>
Signed-off-by: monai-bot <monai.miccai2019@gmail.com>
Signed-off-by: Nic Ma <nma@nvidia.com>
2300 decollate non batch
Signed-off-by: Nic Ma <nma@nvidia.com>
|
As this is a big feature update, I created a branch feature/2220-decollate in Project-MONAI repo. Thanks. |
…2315) * [WIP] 2220 Decollate batch into list of tensors after model forward (#2244) * [DLMED] add support for Activation transform Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] change all the array level post transforms to channel-first Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] update all the IO, utility, post transforms Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] update engines for list of dict Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] update all the event handlers Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] support non-batch data Signed-off-by: Nic Ma <nma@nvidia.com> * [MONAI] python code formatting Signed-off-by: monai-bot <monai.miccai2019@gmail.com> * [DLMED] update according to comments Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] update based on the latest APIs Signed-off-by: Nic Ma <nma@nvidia.com> Co-authored-by: monai-bot <monai.miccai2019@gmail.com> * [MONAI] python code formatting Signed-off-by: monai-bot <monai.miccai2019@gmail.com> * [DLMED] fix all the unit tests Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] fix unit tests Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] fix flake8 issues Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] remove unused import Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] fix flake8 issue Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] fix integration test Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] fix integration tests Signed-off-by: Nic Ma <nma@nvidia.com> * [MONAI] python code formatting Signed-off-by: monai-bot <monai.miccai2019@gmail.com> * [DLMED] fix integration tests Signed-off-by: Nic Ma <nma@nvidia.com> * [MONAI] python code formatting Signed-off-by: monai-bot <monai.miccai2019@gmail.com> * [DLMED] fix flake8 issue Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] add support to copy scalar Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] fix flake8 issue Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] fix wrong unit tests Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] fix doc issue Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] fix broken tests Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] fix unit tests Signed-off-by: Nic Ma <nma@nvidia.com> * [MONAI] python code formatting Signed-off-by: monai-bot <monai.miccai2019@gmail.com> * [DLMED] simplify CSV saver Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] update according to comments Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] add copy_scalar_to_batch util Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] fix flake8 issue Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] change to preprocessing and postprocessing Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] change file name to postprocessing Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] fix flake8 Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] fix typo in doc-string Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] add Decollated back Signed-off-by: Nic Ma <nma@nvidia.com> * [MONAI] python code formatting Signed-off-by: monai-bot <monai.miccai2019@gmail.com> * [DLMED] update according to comments Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] update to use ignite v0.4.5 metrics API Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] fix flake8 issue Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] fix conflicts Signed-off-by: Nic Ma <nma@nvidia.com> * [MONAI] python code formatting Signed-off-by: monai-bot <monai.miccai2019@gmail.com> * fixes #2452 Signed-off-by: Wenqi Li <wenqil@nvidia.com> Co-authored-by: monai-bot <monai.miccai2019@gmail.com>
Description
This PR added support to handle list of Tensor in post transforms.
Status
Work in progress
Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests.make htmlcommand in thedocs/folder.