When does Pytorch Dataset or Dataloader class convert numpy array to Tensor

Previously I directly save my data in numpy array when defining the dataset using data.Dataset, and use data.Dataloader to get a dataloader, then when I trying to use this dataloader, it will give me a tensor. However, this time my data is a little bit complex, so I save it as a dict, the value of each item is still numpy, I find the data.Dataset or data.DataLoader doesn’t convert it into Tensor automatically. I wonder when and how does pytorch data.Dataset or data.DataLoader do the convertion from numpy array to Tensor?

Thanks a lot !

1 Like

The collate_fn and in particular default_collate would transform the bumpy arrays to tensors.


Thanks a lot for your reply!