diff --git a/monai/transforms/utils.py b/monai/transforms/utils.py index ea3577159d..111bfa1102 100644 --- a/monai/transforms/utils.py +++ b/monai/transforms/utils.py @@ -569,9 +569,10 @@ def generate_label_classes_crop_centers( raise ValueError(f"ratios should not contain negative number, got {ratios_}.") for i, array in enumerate(indices): - if len(array) == 0 and warn: - warnings.warn(f"no available indices of class {i} to crop, set the crop ratio of this class to zero.") + 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.") centers = [] classes = rand_state.choice(len(ratios_), size=num_samples, p=np.asarray(ratios_) / np.sum(ratios_))