From 58d69c00c41ef4ae0c2b4ab42c9aa545ac771970 Mon Sep 17 00:00:00 2001 From: Szabolcs Botond Lorincz Molnar Date: Mon, 1 Apr 2024 10:31:27 +0200 Subject: [PATCH] ENH: generate_label_classes_crop_centers: warn only if ratio of missing class is not set to 0 --- monai/transforms/utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/monai/transforms/utils.py b/monai/transforms/utils.py index e282ecff24..7dfd4ee062 100644 --- a/monai/transforms/utils.py +++ b/monai/transforms/utils.py @@ -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: + 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_))