I trained the FNN model for the Linear regression problem in PyTorch, saved that model, and now trying to check my model performance by applying with torch.no_grad():. Y_test size is [64000 2] and X_Test size is [64000 2]. Batch_size = 100. I am trying to check the accuracy of my model which is coming to zero every single time. Unable to understand the problem.


X_Test = torch.tensor(PA_DATA[:64000,0:2], dtype=torch.float32)
#output
Y_Test =torch.tensor(PA_DATA[:64000,2:4], dtype=torch.float32)
test_dataset = Data.TensorDataset(X_Test, Y_Test)
testloader = DataLoader(test_dataset, batch_size=100, shuffle=False)

loss_func1 = torch.nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.0001)


running_accuracy = 0.0 
running_test_loss = 0.0 
total = 0
with torch.no_grad():
    model.eval()
    for X_Test,T_Val in testloader:
        
        pred = model(X_Test)
        test_loss = loss_func1(pred,Y_Test)
        _, predicted = torch.max(pred.data, 1) 
        running_test_loss += test_loss.item()
        total += Y_Test.size(0)
        running_accuracy += (predicted == Y_Test).sum().item() 
        Test_loss_value = running_test_loss/len(testloader)
        accuracy = (100 * running_accuracy / total) 
        print(accuracy)

Sometimes it shows an error tensor of size a (100) did not match with tensor size b(2). I tried various things, but can't calculate the accuracy.

accuracy = 0.0
Test Loss: 0.001215781958308071

RuntimeError: The size of tensor a (100) must match the size of tensor b (64000) at non-singleton dimension 0
0

There are 0 answers