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

About SubjectLoader and Queue #1266

Open
1 task done
LucaLumetti opened this issue Feb 4, 2025 · 0 comments
Open
1 task done

About SubjectLoader and Queue #1266

LucaLumetti opened this issue Feb 4, 2025 · 0 comments

Comments

@LucaLumetti
Copy link
Contributor

LucaLumetti commented Feb 4, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Problem summary

Hello there,
I recently updated torch from version <2.3 to 2.5 and a new warning appeared in my stdout:
UserWarning: Using TorchIO images without a torchio.SubjectsLoader in PyTorch >= 2.3 might have unexpected consequences, e.g., the collated batches will be instances of torchio.Subject with 5D images. Replace your PyTorch DataLoader with a torchio.SubjectsLoader so that the collated batch becomes a dictionary, as expected. See https://github.com/fepegar/torchio/issues/1179 for more context about this issue.

So as suggested, I changed my DataLoader to SubjectLoader, but the warning did not disappear.
So I delved deeper and found that Queue creates a DataLoader, which causes the message above.

subjects_loader = DataLoader(

My code is nearly the same as the example on the docs page: https://torchio.readthedocs.io/patches/patch_training.html
I have also attached the code below in case I missed something important.

I am not sure if this is something intended or if there is maybe something wrong with the way I used Queue and SubjectLoader in my code. As Queue used directly a DataLoader, it is unclear how I can fix this error message.
When I iterate through the subjectloader, I get a dict as expected and everything still works as before.

I also noticed that in_torch_loader() is not extremely fast (still not a bottleneck for sure in my code), maybe a way to disable it would be helpful?

Thanks!

Code for reproduction

dataset = tio.SubjectsDataset(
    subjects,
    transform=transforms,
)
patch_sampler = tio.data.LabelSampler(
    patch_size=(96, 96, 96),
    label_probabilities=label_probs,
)
patches_queue = tio.Queue(
    subjects_dataset=dataset,
    max_length=15,
    samples_per_volume=3,
    sampler=patch_sampler,
    num_workers=num_workers,
)

patches_loader = tio.SubjectsLoader(
    patches_queue,
    batch_size=batch_size,
    shuffle=True,
    num_workers=0,
)

Actual outcome

Multiple warnings (i guess one for each num_workers):
UserWarning: Using TorchIO images without a torchio.SubjectsLoader in PyTorch >= 2.3 might have unexpected consequences, e.g., the collated batches will be instances of torchio.Subject with 5D images. Replace your PyTorch DataLoader with a torchio.SubjectsLoader so that the collated batch becomes a dictionary, as expected. See https://github.com/fepegar/torchio/issues/1179 for more context about this issue.

Error messages

`UserWarning: Using TorchIO images without a torchio.SubjectsLoader in PyTorch >= 2.3 might have unexpected consequences, e.g., the collated batches will be instances of torchio.Subject with 5D images. Replace your PyTorch DataLoader with a torchio.SubjectsLoader so that the collated batch becomes a dictionary, as expected. See https://github.com/fepegar/torchio/issues/1179 for more context about this issue.`

Expected outcome

I would expect the warning to disappear

System info

Platform:   Linux-5.15.0-117-generic-x86_64-with-glibc2.35
TorchIO:    0.20.3
PyTorch:    2.5.1+cu118
SimpleITK:  2.4.1 (ITK 5.4)
NumPy:      1.26.3
Python:     3.9.13 (main, Aug 25 2022, 23:26:10) 
[GCC 11.2.0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant