Skip to content

ProbMapProducer raises IndexError on numpy 2.x: SlidingPatchWSIDataset emits float locations #9135

Description

@nilapate

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:

  1. Install: pip install "monai==1.6.1" "numpy>=2.0" torch tifffile
  2. Run:
    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)
    Output: float64 (expected an integer dtype)
  3. Run sliding-window WSI inference with ProbMapProducer attached. It raises at monai/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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions