Skip to content
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

Random Anisotropy transform changes the shape of the subject when copy=False #1268

Open
1 task done
c-winder opened this issue Feb 12, 2025 · 0 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@c-winder
Copy link
Contributor

c-winder commented Feb 12, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Bug summary

Random Anisotropy transform changes the shape of the subject when copy=False.

Code for reproduction

import torchio as tio
import torch

subject = tio.Subject(
    scan=tio.ScalarImage(tensor=(torch.ones([1, 256, 256, 256])))
)

transform_copy = tio.RandomAnisotropy(
    downsampling=2.5,
    p=1,
    copy=True,
)

transform_no_copy = tio.RandomAnisotropy(
    downsampling=2.5,
    p=1,
    copy=False,
)

shape_original = subject.shape
shape_after_copy_transform = transform_copy(subject).shape
shape_after_no_copy_transform = transform_no_copy(subject).shape

print(f'{shape_original=}')
print(f'{shape_after_copy_transform=}')
print(f'{shape_after_no_copy_transform=}')

Actual outcome

It reduces one of the dimensions, with the dimension changing at random, e.g.

input shape = [1, 256, 256, 256]
output shape may be [1, 103, 256, 256], [1, 256, 103, 256], or [1, 256, 256, 103]

This worked previously when I was using TorchIO: 0.19.7 and PyTorch: 2.0.1.
Error started when I upgraded to TorchIO: 0.20.4 and PyTorch: 2.6

Error messages

shape_original=(1, 256, 256, 256)
shape_after_copy_transform=(1, 256, 256, 256)
shape_after_no_copy_transform=(1, 256, 256, 103)

or 

shape_original=(1, 256, 256, 256)
shape_after_copy_transform=(1, 256, 256, 256)
shape_after_no_copy_transform=(1, 256, 103, 256)

or 

shape_original=(1, 256, 256, 256)
shape_after_copy_transform=(1, 256, 256, 256)
shape_after_no_copy_transform=(1, 103, 256, 256)

Expected outcome

Shape should not change

shape_original=(1, 256, 256, 256)
shape_after_copy_transform=(1, 256, 256, 256)
shape_after_no_copy_transform=(1, 256, 256, 256)

System info

Platform:   Windows-10-10.0.19045-SP0
TorchIO:    0.20.4
PyTorch:    2.6.0+cu126
SimpleITK:  2.4.1 (ITK 5.4)
NumPy:      2.2.2
Python:     3.12.8 | packaged by conda-forge | (main, Dec  5 2024, 14:06:27) [MSC v.1942 64 bit (AMD64)]
@c-winder c-winder added the bug Something isn't working label Feb 12, 2025
@c-winder c-winder changed the title Random Anisotrophy transform changes the shape of the subject when copy=False Random Anisotropy transform changes the shape of the subject when copy=False Feb 12, 2025
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

No branches or pull requests

1 participant