question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent shapes for diffusion MRI

See original GitHub issue

Hi all, I am willing to use Torchio for diffusion MRI and this data is 4D. My plan is to use TorchIO for a patch-based regression where both the input and the output are diffusion MR images. To sample the patches, I am planning to use the intra-cranial mask as a sampling prior.

I ran the following code to try to apply a rotation transform to a subject and I have a ValueError: Images in sample have inconsistent shapes. I would appreciate any help with that issue.

import torchio
from torchio.transforms import RandomAffine


image = '/xxx/aylj.nii.gz'
label = '/xxxx/aylj.nii.gz'
sample = '/xxxx/maskaylj.nii.gz'
subject = torchio.Subject(dMRI=torchio.Image(image, type=torchio.INTENSITY),
                          label=torchio.Image(image, type=torchio.INTENSITY),
                          sampling_map=torchio.Image(sample, type=torchio.SAMPLING_MAP))


transform = RandomAffine(degrees=(-10, 10),
                         isotropic=True)

transformed = transform(subject)

patch_size = 64
sampler = torchio.data.WeightedSampler(patch_size, probability_map='sampling_map')
sample = torchio.ImagesDataset([transformed])[0]
Traceback (most recent call last):
  File "test_torchio.py", line 17, in <module>
    transformed = transform(subject)
  File "/home/ol18/miniconda3/envs/tract_uncertainty/lib/python3.6/site-packages/torchio/transforms/augmentation/random_transform.py", line 33, in __call__
    return super().__call__(sample)
  File "/home/ol18/miniconda3/envs/tract_uncertainty/lib/python3.6/site-packages/torchio/transforms/transform.py", line 62, in __call__
    transformed = self.apply_transform(sample)
  File "/home/ol18/miniconda3/envs/tract_uncertainty/lib/python3.6/site-packages/torchio/transforms/augmentation/spatial/random_affine.py", line 154, in apply_transform
    sample.check_consistent_shape()
  File "/home/ol18/miniconda3/envs/tract_uncertainty/lib/python3.6/site-packages/torchio/data/subject.py", line 122, in check_consistent_shape
    raise ValueError(message)
ValueError: Images in sample have inconsistent shapes:
{'dMRI': (1, 128, 128, 69, 15),
 'label': (1, 128, 128, 69, 15),
 'sampling_map': (1, 128, 128, 69)}

Additionally, If I remove the sample from the Subject, the following error is raised:

Traceback (most recent call last):
  File "test_torchio.py", line 15, in <module>
    transformed = transform(subject)
  File "/home/ol18/miniconda3/envs/tract_uncertainty/lib/python3.6/site-packages/torchio/transforms/augmentation/random_transform.py", line 33, in __call__
    return super().__call__(sample)
  File "/home/ol18/miniconda3/envs/tract_uncertainty/lib/python3.6/site-packages/torchio/transforms/transform.py", line 62, in __call__
    transformed = self.apply_transform(sample)
  File "/home/ol18/miniconda3/envs/tract_uncertainty/lib/python3.6/site-packages/torchio/transforms/augmentation/spatial/random_affine.py", line 184, in apply_transform
    center_lps=center,
  File "/home/ol18/miniconda3/envs/tract_uncertainty/lib/python3.6/site-packages/torchio/transforms/augmentation/spatial/random_affine.py", line 204, in apply_affine_transform
    assert tensor.ndim == 4
AssertionError

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
OeslleLucenacommented, Aug 17, 2020

@fepegar sure! I would do that 😃

1reaction
OeslleLucenacommented, Jul 21, 2020

I guess that might work temporarily. I will see if I can write my scripts based on that workaround. Thanks @fepegar

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inconsistent Shapes for diffusion MRI · Issue #233 - GitHub
Hi all, I willing to use Torchio for diffusion MRI and this data is 4D. My plan is to use TorchIO for a...
Read more >
Does diffusion MRI tell us anything about the white matter? An ...
The main assumption underlying VBM is that the normalization will place corresponding anatomy at the same location across subjects. Precise ...
Read more >
Diffusion MRI anisotropy in the cerebral cortex is determined ...
Here we investigate the determinants of diffusion in the cerebral cortex. Specifically, we ask whether myelinated axons significantly shape dMRI ...
Read more >
Why & How: Diffusion MRI Made Ridiculously Simple - YouTube
Hong-Hsi Lee, Postdoctoral FellowMGH Martinos Center for Biomedical ImagingDiffusion MRI Made Ridiculously SimpleWhy & How, 7 October ...
Read more >
DWI - Questions and Answers ​in MRI
The Stejskal–Tanner equation generalized for any gradient shape—an overview of most pulse sequences measuring free diffusion. Concepts Magn Reson Part A 2012; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found