MONAI icon indicating copy to clipboard operation
MONAI copied to clipboard

MeanEnsemble to accumulate results in-place

Open wyli opened this issue 3 years ago • 1 comments

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.

wyli avatar Apr 14 '23 17:04 wyli

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?

staydelight avatar Oct 01 '24 08:10 staydelight