Pytorch model 2D regression given an scalar input
I want to create a model to perform this regression:

My dataset looks like:
t,x,y
0.0,-,0.5759052335487023
0.01,-,-
0.02,1.1159124144549086,-
0.03,-,-
0.04,1.0054825084650338,0.4775267298487888
0.05,-,-

I'm having some troubles with loss, dataset load, batch_size, and Net structure (I add one single layer to simplify the problem)
Thats my code:
Net:
class Net(nn.Module):
    '''Model to regress 2d time series values given scalar input.'''
    def __init__(self):
        super(Net, self).__init__()
        #Layers
        self.predict = nn.Linear(1, 2) 

    def forward(self, x):
        x = self.predict(x)
        return x

Dataset load
class TimeSeriesDataset(torch.utils.data.Dataset):

    def __init__(self, csv_file):
        #Load the dataset
        #Load the csv file as a dataframe
        df = pd.read_csv(csv_file, header=0, na_values='-')
        #Store the inputs and outputs
        self.x = df.values[:,:-2].astype('float32')
        self.y = df.values[:,1:].astype('float32')
        #Ensure target has the right shape
        self.y = self.y.reshape((len(self.y),2))

    def __len__(self):
        #Return the number of rows in the dataset
        return len(self.x)

    def __getitem__(self, idx):
        #Return a row at an index
        return [self.x[idx], self.y[idx]]

Trainloader, loss, optimizer
dataset = TimeSeriesDataset('data.csv')
trainloader = torch.utils.data.DataLoader(
    dataset, batch_size=32, shuffle=True, num_workers=2)

def lossFunc(outputs, labels):
  # nn.MSELoss() #Mean Squared Error, works fine with regression problems and with small numbers (x-y)^2
  return torch.mean((outputs-labels)**2)

net = Net()
optimizer = torch.optim.SGD(net.parameters(), lr=0.01)
print(net)

Trainning:
for epoch in range(300):

    running_loss = 0.0
    for i, data in enumerate(trainloader, 0):
        # TODO get the data
        # inputs, labels
        inputs, labels = data
        # zero the parameter gradients
        optimizer.zero_grad()

        # forward + backward + optimize
        outputs = net(inputs)
        #print(&quot;Inputs&quot;, inputs)
        #print(&quot;labels&quot;, labels)
        #print(&quot;outputs&quot;, outputs)
        loss = lossFunc(outputs, labels)
        loss.backward()
        optimizer.step()
        
        # print statistics
        running_loss += loss.item()
        if i % 20 == 19:    # print every 20 mini-batches
            print('[%d, %5d] loss: %.3f' %
                  (epoch + 1, i + 1, running_loss / 20))
            running_loss = 0.0

print('Finished Training')

Outputs looks this way:
tensor([[nan, nan],
        [nan, nan],
        [nan, nan],
...

And when I execute the 300 epochs error value doesn't change and prints nan

After the line loss = loss(outputs, labels), loss is now a tensor, not a function anymore. Python does not allow you to have distinct objects with identical names.
So after the first call, loss has become a tensor, and as the error says &quot;tensors are not callable&quot;, so the second call fails
