Order of dimensions in torchio vs pytorch tensors #798
Replies: 3 comments 13 replies
-
Hi, @Elmisiry99. The concepts of width, height and depth are not very well defined for 3D images. The anatomical correspondence of each dimension depends on the images' orientation. I suggest you normalize their orientations using Regarding your second question, you can just pass the transform to the dataset class, instead of performing it on the tensor extracted from the collated batch. Additionally, the typing hint is not correct, as that |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for your help, you really clarified a lot of things that I didn't fully understand :). |
Beta Was this translation helpful? Give feedback.
-
Can you share the whole error message?
…On Mon, 31 Jan 2022, 04:16 Elmisiry99, ***@***.***> wrote:
I tried to override *getitem*() but I got this error:
TypeError: object of type 'type' has no len()
Code looks like this:
training_dataset = tio.SubjectsDataset(training_2examples, transform=training_transforms)
class training_dataset(tio.SubjectsDataset):
def __len__(self):
return len(self._subjects)
def __getitem__(self, index: int):
subject = self._subjects[index]
subject = copy.deepcopy(subject)
if self.load_getitem:
subject.load()
subject1 = self._transform(subject)
subject2 = self._transform(subject)
return subject1, subject2
Could please tell me what is wrong here. Thanks in advance
—
Reply to this email directly, view it on GitHub
<#798 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADAZVVGFP3GZEGL6GZGXXMDUYYEIJANCNFSM5MP6ZOXQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hello,
I have been struggling with the issue of not knowing how does torchio saves the images it loads.
In the documentation of torchio, it is mentioned that when creating a ScalarImage(alone or in a subject), I have to pass either the path to the image or a 4D tensor. Normally, images are represented in pytorch as (B,C,D,H,W). On the other hand, torchio changes this order to (C,W,H,D), discarding the batch dimensions as it is not relevant in this case. My question is as follows:
Does torchio when input a tensor (C,D,H,W) rearranges it first to (C,W,H,D) or does it performs the transformation on the original tensor with the assumption that it is (C,W,H,D)?
I am concerned about this, as I am using torchio to define the dataset I use for the model I am working on and I am getting oscillating curves in the training loss. So I wanted to make sure that images I feed to the network are the right ones and I am not doing an indexing errors. I train the network using 2D slices sampled from the volumes I load using torchio. That is why I have to first apply the transforms on the whole 3D image, then slice this volume to access the desired 2D images.
Also I have another question regarding batches and torchio. Should I start a new discission for it or can I mention it here?
The following snippet contains an example of what I mean
Beta Was this translation helpful? Give feedback.
All reactions