Skip to content

Commit d118aa7

Browse files
authored
Add single if statement for warn (#6130)
Avoids crashing of the function if `ratios_[i] = 0` cannot be updated Fixes #6121 ### Description Adds additional if statement to check if warn is true, so that the following code can still be executed. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] 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. --------- Signed-off-by: kbressem <kenobressem@gmail.com>
1 parent 354c9c2 commit d118aa7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

monai/transforms/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,10 @@ def generate_label_classes_crop_centers(
569569
raise ValueError(f"ratios should not contain negative number, got {ratios_}.")
570570

571571
for i, array in enumerate(indices):
572-
if len(array) == 0 and warn:
573-
warnings.warn(f"no available indices of class {i} to crop, set the crop ratio of this class to zero.")
572+
if len(array) == 0:
574573
ratios_[i] = 0
574+
if warn:
575+
warnings.warn(f"no available indices of class {i} to crop, set the crop ratio of this class to zero.")
575576

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

0 commit comments

Comments
 (0)