Skip to content

Commit f4992bd

Browse files
committed
Add single if statement for warn
Avoids crashing of the function if `ratios_[i] = 0` cannot be updated
1 parent 354c9c2 commit f4992bd

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,8 +569,9 @@ 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:
573+
if warn:
574+
warnings.warn(f"no available indices of class {i} to crop, set the crop ratio of this class to zero.")
574575
ratios_[i] = 0
575576

576577
centers = []

0 commit comments

Comments
 (0)