Hello PyTorch Community!
I want to return a SimpleITK.SimpleITK.Image from my data loader as my model needs it at some stage, I am getting following error.
TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class ‘SimpleITK.SimpleITK.Image’>
As the error message describes you would need to transform your SimpleITK.Image to a tensor or another data type PyTorch understands. You could alternatively also create a custom collate_fn, which could deal with your data type, but would eventually still need to transform it to a tensor before feeding it into a model.
Thanks for the reply. I cannot convert because the formation related to spacing, angles, and directions, and some related parameters are lost, and my model uses this information at a later stage.
As an alternative, I am returning the path of SimpleITK.SimpleITK.Image and later will read them during the training/inference stage.
Wouldn’t it be possible to return the transformed image as a tensor with all needed metadata together?
At one point you would still need to transform the image, so I’m unsure why not in the __getitem__ method to avoid the error.