Skip to content

Commit 49b1012

Browse files
authored
fix(apps/nuclick): replace np.random.choice with self.R.choice in Add… (#8836)
Fixes #6888 (partial) - follow-up to #8798 ### Description In `AddPointGuidanceSignald.exclusion_map` (`monai/apps/nuclick/transforms.py`), two calls used `np.random.choice` (global NumPy random state) instead of `self.R.choice`. Since `AddPointGuidanceSignald` already inherits from `Randomizable`, this is a straightforward replacement that ensures reproducibility when `set_determinism()` or manual seeding is used. **Before:** ```python if np.random.choice([True, False], p=[drop_rate, 1 - drop_rate]): ``` **After:** ```python if self.R.choice([True, False], p=[drop_rate, 1 - drop_rate]): ``` PR #8798 already fixed `np.random.*` calls in transforms and data utilities. This PR continues that work for the two remaining calls in `apps/nuclick/transforms.py` mentioned in #6888. ### Types of changes - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. Signed-off-by: Zeeshan Modi <92383127+Zeesejo@users.noreply.github.com>
1 parent 71f16ed commit 49b1012

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

monai/apps/nuclick/transforms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,14 @@ def inclusion_map(self, mask, dtype):
367367

368368
def exclusion_map(self, others, dtype, jitter_range, drop_rate):
369369
point_mask = torch.zeros_like(others, dtype=dtype)
370-
if np.random.choice([True, False], p=[drop_rate, 1 - drop_rate]):
370+
if self.R.choice([True, False], p=[drop_rate, 1 - drop_rate]):
371371
return point_mask
372372

373373
max_x = point_mask.shape[0] - 1
374374
max_y = point_mask.shape[1] - 1
375375
stats = measure.regionprops(convert_to_numpy(others))
376376
for stat in stats:
377-
if np.random.choice([True, False], p=[drop_rate, 1 - drop_rate]):
377+
if self.R.choice([True, False], p=[drop_rate, 1 - drop_rate]):
378378
continue
379379

380380
# random jitter

0 commit comments

Comments
 (0)