Replies: 4 comments 2 replies
-
Hello yes the way sampler are written assume the data is read within the Subject (data key). So GridSampler for instance will set a given location and will extract directly from the tensor data stored in torchio Subject. If I understand correctly what you propose, this imply to change not only the Subject class but also all Sampler (so that instead of getting a subpart of subject tensor data it will call the subject.load_path at a given location but I am not sure ... may be @fepegar have a better overview of this issue ? An other option is may be to define a new DataLoader for you histo data. Instead to have on subject per file you can implement a method, that give a subject (containing a patch of you all image at a random / given location) I hope I am clear enough, although I am not so sure, but it is worth to specify a bit what the objectives are. An important question is when to apply the torchio transforms ? |
Beta Was this translation helpful? Give feedback.
-
Hi, and thanks for the comprehensive answer, it is indeed clear. I might just return to this problem after my master's. Perhaps with the insight I will have gained by then, I will work on proposing an integration to |
Beta Was this translation helpful? Give feedback.
-
I think it is an important improvement for the histopathology community I understand making a proper PR will be more work, but do not hesitate to copy past your quick solution, it may help future dev on this topic |
Beta Was this translation helpful? Give feedback.
-
The import nibabel as nib
import torchio as tio
img_path = tio.datasets.Colin27().t1.path
class LazyImage:
def __init__(self, path):
self._img = nib.load(path)
self.data = self._img.dataobj
lazy_image = LazyImage(img_path)
lazy_image.data[10:12, 20:23] array([[[353901.94043323, 386856.37203756, 379041.10352266, ...,
14849.03239323, 12374.19390786, 12634.70384569],
[321208.02172872, 356897.8150852 , 420983.11169106, ...,
34647.7447192 , 26441.69796861, 17975.14572317],
[394020.38199884, 423588.19329739, 414079.59093368, ...,
54316.19911427, 44156.33523495, 45068.11853635]],
[[356354.79947558, 375317.05337393, 383579.17947158, ...,
11512.79256673, 10564.68046421, 10835.56995371],
[361095.35702619, 393737.52385029, 407011.09920955, ...,
26411.70190102, 26411.70190102, 12596.35052475],
[368003.04826477, 373014.49752638, 416356.76845527, ...,
62710.86239374, 45915.72737341, 39685.27429829]]]) I suppose you could add a subclass of |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am dealing with histopathology 2D images, which I found torchio to be perfect! I wanted to optimize inference memory-wise with
GridAggregator
.The way I understand it, torchio needs to first load the whole image into RAM, and only then it can extract patches and push them to the GPU VRAM. Is it true? I am talking from the perspective of libraries like OpenSlide and pyvips which can read in a patch at a time.
Would it be possible to write a custom reader that will read in only the specified region of the image? I've thought about returning a custom class from the
Subject
and calling it withtio.LOCATION
, so something like:But I don't really know if it's going to fit with torchio model.
Beta Was this translation helpful? Give feedback.
All reactions