Skip to content
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: 5 additions & 4 deletions monai/transforms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,16 @@ def _correct_centers(
return center_ori

centers = []
fg_indices, bg_indices = np.asarray(fg_indices), np.asarray(bg_indices)
if fg_indices.size == 0 and bg_indices.size == 0:
raise ValueError("No sampling location available.")

if not len(fg_indices) or not len(bg_indices):
if not len(fg_indices) and not len(bg_indices):
raise ValueError("No sampling location available.")
if fg_indices.size == 0 or bg_indices.size == 0:
warnings.warn(
f"N foreground {len(fg_indices)}, N background {len(bg_indices)},"
"unable to generate class balanced samples."
)
pos_ratio = 0 if not len(fg_indices) else 1
pos_ratio = 0 if fg_indices.size == 0 else 1

for _ in range(num_samples):
indices_to_use = fg_indices if rand_state.rand() < pos_ratio else bg_indices
Expand Down