[WIP] 2220 Decollate batch into list of tensors after model forward#2244
Conversation
|
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 <[email protected]>
|
Hi @wyli , Thanks for your suggestions. Thanks. |
Signed-off-by: Nic Ma <[email protected]>
|
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 |
|
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 <[email protected]>
merge master
Signed-off-by: Nic Ma <[email protected]>
Signed-off-by: monai-bot <[email protected]>
Signed-off-by: Nic Ma <[email protected]>
2300 decollate non batch
Signed-off-by: Nic Ma <[email protected]>
|
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 <[email protected]> * [DLMED] change all the array level post transforms to channel-first Signed-off-by: Nic Ma <[email protected]> * [DLMED] update all the IO, utility, post transforms Signed-off-by: Nic Ma <[email protected]> * [DLMED] update engines for list of dict Signed-off-by: Nic Ma <[email protected]> * [DLMED] update all the event handlers Signed-off-by: Nic Ma <[email protected]> * [DLMED] support non-batch data Signed-off-by: Nic Ma <[email protected]> * [MONAI] python code formatting Signed-off-by: monai-bot <[email protected]> * [DLMED] update according to comments Signed-off-by: Nic Ma <[email protected]> * [DLMED] update based on the latest APIs Signed-off-by: Nic Ma <[email protected]> Co-authored-by: monai-bot <[email protected]> * [MONAI] python code formatting Signed-off-by: monai-bot <[email protected]> * [DLMED] fix all the unit tests Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix unit tests Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix flake8 issues Signed-off-by: Nic Ma <[email protected]> * [DLMED] remove unused import Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix flake8 issue Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix integration test Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix integration tests Signed-off-by: Nic Ma <[email protected]> * [MONAI] python code formatting Signed-off-by: monai-bot <[email protected]> * [DLMED] fix integration tests Signed-off-by: Nic Ma <[email protected]> * [MONAI] python code formatting Signed-off-by: monai-bot <[email protected]> * [DLMED] fix flake8 issue Signed-off-by: Nic Ma <[email protected]> * [DLMED] add support to copy scalar Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix flake8 issue Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix wrong unit tests Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix doc issue Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix broken tests Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix unit tests Signed-off-by: Nic Ma <[email protected]> * [MONAI] python code formatting Signed-off-by: monai-bot <[email protected]> * [DLMED] simplify CSV saver Signed-off-by: Nic Ma <[email protected]> * [DLMED] update according to comments Signed-off-by: Nic Ma <[email protected]> * [DLMED] add copy_scalar_to_batch util Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix flake8 issue Signed-off-by: Nic Ma <[email protected]> * [DLMED] change to preprocessing and postprocessing Signed-off-by: Nic Ma <[email protected]> * [DLMED] change file name to postprocessing Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix flake8 Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix typo in doc-string Signed-off-by: Nic Ma <[email protected]> * [DLMED] add Decollated back Signed-off-by: Nic Ma <[email protected]> * [MONAI] python code formatting Signed-off-by: monai-bot <[email protected]> * [DLMED] update according to comments Signed-off-by: Nic Ma <[email protected]> * [DLMED] update to use ignite v0.4.5 metrics API Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix flake8 issue Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix conflicts Signed-off-by: Nic Ma <[email protected]> * [MONAI] python code formatting Signed-off-by: monai-bot <[email protected]> * fixes #2452 Signed-off-by: Wenqi Li <[email protected]> Co-authored-by: monai-bot <[email protected]>
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.