Below is program of data loader.
Doubt: x_data and y_data was already made a tensor by this statement:-
self.x_data=from_numpy(xy[:,:-1])
Then why  again converting it to tensor
inputs,labels=tensor(inputs),tensor(labels)
Full code:-
from torch.utils.data import Dataset,DataLoader
from torch import from_numpy,tensor
import numpy as np
class DiabetesDataset(Dataset):
def init(self):
xy=np.loadtxt(’/content/diabetes.csv’,delimiter=’,’,dtype=np.float32)
self.len=xy.shape[0]
self.x_data=from_numpy(xy[:,:-1])
self.y_data=from_numpy(xy[:,[-1]])
def getitem(self,index):
return self.x_data[index],self.y_data[index]
def len(self):
return self.len
dataset=DiabetesDataset()
trainLoader=DataLoader(dataset=dataset,
batch_size=32,
shuffle=True,
num_workers=2)
for epoch in range(2):
for i,data in enumerate(train_loader,0):
inputs,labels=data
inputs,labels=tensor(inputs),tensor(labels)
print(f'Epoch: {i}|Inputs:{inputs.data} | Labels:{labels.data} ')