Pytorch customized data loader

Would you like to load each file as one sample or is a whole batch saved in each file?
Were you able to load the data using scipy.io.loadmat?
Here is a dummy example for your dataset:


class MyDataset(Dataset):
    def __init__(self, mat_paths):
        self.paths = mat_paths
        
    def __getitem__(self, index):
        # Load .mat
        data = io.loadmat(self.paths[index])
        x = torch.from_numpy(data['Training_patches'])
        y = torch.from_numpy(data['labels'])
        
        return x, y
    
    def __len__(self):
        return len(self.paths)
2 Likes