I am coding Dataloader for my own data. I return output as numpy but dataloader gives me torch.Tensor as the output. Don’t understand why.
from torch.utils import data
import torch
import nibabel as nib

class getdata(data.Dataset):
    '''
    Initializes a dataset for the network
    Assumes that the data_dir has files named MRimages and CTimages that contain all the images 
    for all the patients in .hdr format.
    '''
    def __init__(self,data_dir,transform):
        'Initialization'
        self.data_dir = data_dir
        self.transform = transform
        self.list_IDs = np.arange(nib.load(self.data_dir+ '/MRimages.img').shape[2]) #list of all patients.
        
    def __len__(self):
        'Total no. of samples. Make sure that number of MR and CT samples are same.'
        num = len(self.list_IDs)  #total number of slices.
        return num
        
    def __getitem__(self,index): #index is patient ID
        'Generate one sample of data'
        ID = self.list_IDs[index]
        MR = np.asarray(nib.load(self.data_dir+ '/MRimages.img').get_data()[:,:,ID])
        CT = np.asarray(nib.load(self.data_dir+ '/CTimages.img').get_data()[:,:,ID])

        sample = {'MR': MR,'CT': CT}
        if self.transform:
            sample = self.transform(sample)

        return sample

Calling function:
data_dir = '...'#my data directory
a = np.arange(nib.load(data_dir+ '/MRimages.img').shape[2])
params = {'batch_size': 64,
          'shuffle': True,
          'num_workers': 2}
train_set = getdata(data_dir,transform=None)
train_gen = data.DataLoader(train_set,**params)
for s in train_gen:
    print(type(s['MR']))

This gives me <class ‘torch.Tensor’> for every batch.
I want to make the self.tranform as class that works on numpy matrix and not torch matrix.
Any suggestions?