I would try to use the original numpy array and converted into torch tensor here:
class Dataset(Dataset):
    def __getitem__(this, idx):
        if this.mode == "train":
            return torch.from_numpy(this.X[idx]).float(), torch.from_numpy(this.y[idx]).long()
        else:
            return torch.from_numpy(this.X[idx]).float()

Your original back tracing is interesting



 krishna511:

File “C:\Users\krishna\Anaconda3\lib\site-packages\torch\utils\data_utils\fetch.py”, line 47, in fetch
return self.collate_fn(data)
File “C:\Users\krishna\Anaconda3\lib\site-packages\torch\utils\data_utils\collate.py”, line 83, in default_collate
return [default_collate(samples) for samples in transposed]
File “C:\Users\krishna\Anaconda3\lib\site-packages\torch\utils\data_utils\collate.py”, line 83, in
return [default_collate(samples) for samples in transposed]


It falls into the logic here pytorch/collate.py at 94cc681fc2e5218c10493938a8ca01272c3c6fc0 · pytorch/pytorch · GitHub 1, which is not expected since you are returning tuple. Can you verify your output by printing out the data like the following code.
class Dataset(Dataset):
    def __getitem__(this, idx):
        if this.mode == "train":
            res =  torch.from_numpy(this.X[idx]).float(), torch.from_numpy(this.y[idx]).long()
            print(res)
            return res
        else:
            return torch.from_numpy(this.X[idx]).float()