Skip to content

Negative strides issue in monai.transforms.LoadImage causes error during collate #7798

@KumoLiu

Description

@KumoLiu

Describe the bug
When using monai.transforms.LoadImage with the nrrdreader to load an NRRD file, the resulting image metadata contains negative strides. This negative strides issue leads to an error when the tensor is collated.

To Reproduce

import monai

# Load an NRRD file
img = monai.transforms.LoadImage(reader="nrrdreader", index_order="C")("wrong_something.nrrd")

print(img.meta['spatial_shape'].strides)  # Output: (-8,)

Error log:

torch/utils/data/_utils/collate.py", line 222, in <listcomp>
    return collate([torch.as_tensor(b) for b in batch], collate_fn_map=collate_fn_map)
ValueError: At least one stride in the given numpy array is negative, and tensors with negative strides are not currently supported. (You can probably work around this by making a copy of your array  with array.copy().)

Test data:
https://drive.google.com/file/d/1Et-khdsou7E2T_aoX0zLvnld49Xh8YDn/view?usp=drive_link

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions