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

ENH: generate_label_classes_crop_centers: warn only if ratio of missing class is not set to 0 #7602

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions monai/transforms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,12 @@ def generate_label_classes_crop_centers(

for i, array in enumerate(indices):
if len(array) == 0:
ratios_[i] = 0
if warn:
warnings.warn(f"no available indices of class {i} to crop, set the crop ratio of this class to zero.")
if ratios_[i] != 0:
ratios_[i] = 0
if warn:
KumoLiu marked this conversation as resolved.
Show resolved Hide resolved
warnings.warn(
f"no available indices of class {i} to crop, setting the crop ratio of this class to zero."
)

centers = []
classes = rand_state.choice(len(ratios_), size=num_samples, p=np.asarray(ratios_) / np.sum(ratios_))
Expand Down
Loading