Transpose axes when making CustomDataset

Hello PyTorch!

Im making custom dataset class and im wondering how i can make the dimension of the batch from dataloader in [10, 100, 13] not [100,10,13], with transpose((1,0,2)), where should i put transpose in my custom dataset??

Please help me!!

Have you read this thread?


I knew how to transpose the axes with transpose((1,0,2) but ,

Im wondering where should i put this to Custom Dataset class.


I don’t think that putting it in Dataset will change anything since batch construction is the task of DataLoader, so your i1.shape (specifically 100), comes directly form it . Moreover PyTorch normal format is NCHW, (the batch dimension is in the 0th position, then colour, height and width), so DataLoader will make it that way. I think the easiest way is to transpose it after getting batch from DataLoader. I don’t know if that satisfy you, or you have to explicitly put this in DataLoader. If you have to put it in DataLoader I think you can do it via collate_fn (docs), but I don’t have experience with that.