-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: dev
Are you sure you want to change the base?
Conversation
Signed-off-by: staydelight <[email protected]>
for more information, see https://pre-commit.ci
Signed-off-by: staydelight <[email protected]>
There was a problem hiding this 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 |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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:
MONAI/monai/transforms/post/array.py
Lines 639 to 644 in bae8f59
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) |
There was a problem hiding this comment.
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?
Fixes #6366 .
Description
According to the description in issue 6366, modify MeanEnsemble.
Types of changes
./runtests.sh -f -u --net --coverage
../runtests.sh --quick --unittests --disttests
.make html
command in thedocs/
folder.