ProbMapProducer raises IndexError on numpy 2.x: SlidingPatchWSIDataset emits float locations
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- data, machine-learning
Research direction
Start with SlidingPatchWSIDataset and MaskedPatchWSIDataset, comparing how each builds ProbMapKeys.LOCATION, then inspect the indexing in monai/handlers/probability_maps.py. Reproduce with NumPy 2.x using the provided snippet and sliding-window inference; done means the location metadata has an integer dtype and ProbMapProducer indexes the probability map without IndexError.
Written by the indexing model from the issue text.
Description
Describe the bug
SlidingPatchWSIDataset builds ProbMapKeys.LOCATION with np.round(...) and never casts back to int, so the metadata is float64. ProbMapProducer uses it directly as an array index, which numpy 2.x rejects:
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`)
and integer or boolean arrays are valid indices
MaskedPatchWSIDataset already calls .astype(int) on the same key, so the two datasets emit different dtypes.
To Reproduce
Steps to reproduce the behavior:
To Reproduce
Steps to reproduce the behavior:
- Install:
pip install "monai==1.6.1" "numpy>=2.0" torch tifffile - Run:
Output:import numpy as np, tifffile, tempfile, os from monai.data import SlidingPatchWSIDataset from monai.utils.enums import WSIPatchKeys, ProbMapKeys path = os.path.join(tempfile.mkdtemp(), "slide.tiff") tifffile.imwrite(path, np.random.randint(0, 255, (4, 4, 3), dtype=np.uint8), photometric="rgb") ds = SlidingPatchWSIDataset( data=[{"image": path, WSIPatchKeys.LEVEL: 0}], patch_size=(2, 2), reader="TiffFile") print(ds.data[0][ProbMapKeys.LOCATION.value].dtype)float64(expected an integer dtype) - Run sliding-window WSI inference with
ProbMapProducerattached. It raises atmonai/handlers/probability_maps.py:self.prob_map[name][tuple(loc)] = prob
Expected behavior
ProbMapKeys.LOCATION should be an integer array, consistent with MaskedPatchWSIDataset, and ProbMapProducer should index the probability map without error.
Screenshots
N/A — traceback included above.
Environment
MONAI version: 1.6.1
Numpy version: 2.5.3
Pytorch version: 2.14.0+cpu
MONAI flags: HAS_EXT=False, USE_COMPILED=False, USE_META_DICT=False
MONAI rev id: 7af492176792f9069b8f1253d099abd05c5e769d
System: Linux
Linux version: Ubuntu 24.04 LTS
Platform: Linux-6.8.0-31-generic-x86_64-with-glibc2.39
Python version: 3.12.3
Minimal venv for reproducing against a released wheel, so optional dependencies report NOT INSTALLED.
- Dominant language
- Python
- Stars
- 8.7k
- Forks
- 1.6k
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 17
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Project-MONAI/MONAI
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Project-MONAI/MONAI#9068 · 2 comments ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Project-MONAI/MONAI#9046 ·
Maintainers usually reply within 3 days
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Project-MONAI/MONAI#9026 ·
Maintainers usually reply within 3 days
-
Difficulty 4/5 3-5 days Newbie friendliness 68/100
Project-MONAI/MONAI#9144 ·
Maintainers usually reply within 3 days
-
PR Update ActionPossibly taken @KumoLiu claimed this 3 days ago. Open
Project-MONAI/MONAI#9141 · 3 assignees ·
Maintainers usually reply within 3 days
All issues in Project-MONAI/MONAI
Similar issues
-
adr
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
kristofdegrave/homeassistant-smart-charging#1607 ·
Maintainers usually reply within 1 day
-
namespace operations
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
EclipseFdn/open-vsx.org#13665 ·
Maintainers usually reply within 1 day
-
doc good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
collective/icalendar#1865 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
canonical/opentelemetry-collector-operator#409 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
mozilla/addons-release-tests#1243 ·
Maintainers usually reply within 1 day