Skip to content

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

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

Closed
KumoLiu opened this issue May 23, 2024 · 0 comments · Fixed by #7809
Closed

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

KumoLiu opened this issue May 23, 2024 · 0 comments · Fixed by #7809
Labels
bug Something isn't working

Comments

@KumoLiu
Copy link
Contributor

KumoLiu commented May 23, 2024

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

@KumoLiu KumoLiu added the bug Something isn't working label May 23, 2024
KumoLiu added a commit to KumoLiu/MONAI that referenced this issue May 27, 2024
Signed-off-by: YunLiu <[email protected]>
ericspod added a commit that referenced this issue May 28, 2024
Fixes #7798

### Description

Add copy to avoid negative strides when save spatial shape.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [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: YunLiu <[email protected]>
Co-authored-by: Eric Kerfoot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant