Skip to content

Commit 816d4af

Browse files
committed
Revert "Add warning if SubjectsLoader is not used in PyTorch >= 2.3 (#1215)"
This reverts commit 5df1638.
1 parent 62cb2cc commit 816d4af

2 files changed

Lines changed: 0 additions & 39 deletions

File tree

src/torchio/data/image.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from ..types import TypeTripletInt
3434
from ..utils import get_stem
3535
from ..utils import guess_external_viewer
36-
from ..utils import in_torch_loader
3736
from ..utils import is_iterable
3837
from ..utils import to_tuple
3938
from .io import check_uint_to_int
@@ -179,7 +178,6 @@ def __init__(
179178
warnings.warn(message, FutureWarning, stacklevel=2)
180179

181180
super().__init__(**kwargs)
182-
self._check_data_loader()
183181
self.path = self._parse_path(path, verify=verify_path)
184182

185183
self[PATH] = '' if self.path is None else str(self.path)
@@ -238,20 +236,6 @@ def __copy__(self):
238236
)
239237
return new_image
240238

241-
@staticmethod
242-
def _check_data_loader() -> None:
243-
if torch.__version__ >= '2.3' and in_torch_loader():
244-
message = (
245-
'Using TorchIO images without a torchio.SubjectsLoader in PyTorch >='
246-
' 2.3 might have unexpected consequences, e.g., the collated batches'
247-
' will be instances of torchio.Subject with 5D images. Replace'
248-
' your PyTorch DataLoader with a torchio.SubjectsLoader so that'
249-
' the collated batch becomes a dictionary, as expected. See'
250-
' https://github.com/TorchIO-project/torchio/issues/1179 for more'
251-
' context about this issue.'
252-
)
253-
warnings.warn(message, stacklevel=1)
254-
255239
@property
256240
def data(self) -> torch.Tensor:
257241
"""Tensor data (same as :class:`Image.tensor`)."""

src/torchio/utils.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import ast
44
import gzip
5-
import inspect
65
import os
76
import shutil
87
import sys
@@ -15,7 +14,6 @@
1514
import numpy as np
1615
import SimpleITK as sitk
1716
import torch
18-
import torch.utils.data.dataloader
1917
from nibabel.nifti1 import Nifti1Image
2018
from torch.utils.data import DataLoader
2119
from torch.utils.data._utils.collate import default_collate
@@ -412,24 +410,3 @@ def is_iterable(object: Any) -> bool:
412410
return True
413411
except TypeError:
414412
return False
415-
416-
417-
def in_class(classes) -> bool:
418-
classes = to_tuple(classes)
419-
stack = inspect.stack()
420-
for frame_info in stack:
421-
instance = frame_info.frame.f_locals.get('self')
422-
if instance is None:
423-
continue
424-
if instance.__class__ in classes:
425-
return True
426-
else:
427-
return False
428-
429-
430-
def in_torch_loader() -> bool:
431-
classes = (
432-
torch.utils.data.dataloader._SingleProcessDataLoaderIter,
433-
torch.utils.data.dataloader._MultiProcessingDataLoaderIter,
434-
)
435-
return in_class(classes)

0 commit comments

Comments
 (0)