MONAI
MONAI copied to clipboard
MeanEnsemble to accumulate results in-place
Describe the bug
https://github.com/Project-MONAI/MONAI/blob/825b8db9b20e0a85b2df327e3f4f23379fef7b2e/monai/transforms/post/array.py#L628-L636
the current implementation keeps all the predictions which take up unnecessary space compared with maintaining an output and updating it in-place.
Hello @wyli ,
I have tried to implement a method using a single output and updating it in-place. Here's the code:
for i, pred in enumerate(img):
pred = torch.as_tensor(pred)
if out_pt is None:
out_pt = torch.zeros_like(pred)
if self.weights is not None:
weight = self.weights[i].to(pred.device)
out_pt += pred * weight
total_weight += weight
out_pt /= total_weight
What do you think about it?