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

Modify MeanEnsemble to accumulate results in-place. #8141

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

staydelight
Copy link
Contributor

Fixes #6366 .

Description

According to the description in issue 6366, modify MeanEnsemble.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

Copy link
Contributor

@KumoLiu KumoLiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, leave several comments.
And also please ensure the unittest pass, the error log shown here: https://github.com/Project-MONAI/MONAI/actions/runs/11289371448/job/31399089589?pr=8141#step:8:14508


img_ = img_ * weights / weights.mean(dim=0, keepdim=True)
out_pt += pred * weight
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If self.weights is None, this line will show error. You may need set a default value or move the computation in the for-loop.

out_pt = None
total_weight = 0.0

for i, pred in enumerate(img):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need check the the type for img what if it's a single array. Something like the change here:

if isinstance(img, Sequence) and isinstance(img[0], np.ndarray):
img = [torch.as_tensor(i) for i in img]
elif isinstance(img, np.ndarray):
img = torch.as_tensor(img)
out: torch.Tensor = torch.stack(img) if isinstance(img, Sequence) else img # type: ignore
return out

out_pt = torch.zeros_like(pred)

if self.weights is not None:
weight = self.weights[i].to(pred.device)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you handle whether self.weights has the same shape with the img?

@staydelight staydelight marked this pull request as draft October 15, 2024 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MeanEnsemble to accumulate results in-place
2 participants