Skip to content

Remove length check in favour of truthiness of the object #1445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 14, 2021
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