Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MeanEnsemble to accumulate results in-place #6366

Open
wyli opened this issue Apr 14, 2023 · 1 comment · May be fixed by #8141
Open

MeanEnsemble to accumulate results in-place #6366

wyli opened this issue Apr 14, 2023 · 1 comment · May be fixed by #8141

Comments

@wyli
Copy link
Contributor

wyli commented Apr 14, 2023

Describe the bug

img_ = self.get_stacked_torch(img)
if self.weights is not None:
self.weights = self.weights.to(img_.device)
shape = tuple(self.weights.shape)
for _ in range(img_.ndimension() - self.weights.ndimension()):
shape += (1,)
weights = self.weights.reshape(*shape)
img_ = img_ * weights / weights.mean(dim=0, keepdim=True)

the current implementation keeps all the predictions which take up unnecessary space compared with maintaining an output and updating it in-place.

@staydelight
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants