Facing problem in creating confusion matrix

I am using following function to predict and eventually plotting confusion matrix. Here I am using CroosEntropyLoss criterion. The model is returning to values, which are tuples, So when I m using this function after saving the training model. It throws the typeError :exp(): argument ‘input’ (position 1) must be Tensor, not tuple. In bold line. What I am grasping is in exp function i need a scaler number and this a tuple, I took the max value of tuple using max() method , but still its giving same error.
Please suggest a solution

def predict_sm(model=None, dataloader=None, device=None, path=None):
    if path:
        model.load_state_dict(torch.load(path))

    model.eval()
    model.to(device)

    y_pred = []
    
    for X, y,y1 in dataloader:
        X = X.to(device)
        with torch.no_grad():
            logProb,_ = model(X)
            
        **Prob = torch.exp(logProb)**
        Pred = torch.argmax(Prob, dim=1).long()
        y_pred.append(list(Pred.detach().cpu().numpy()))
    print(sum(y_pred,[]))
    return sum(y_pred,[])

As you’ve described, the error is raised, since a tensor instead of a tuple is expected.
Could you explain a bit, what the model is returning and what the tuple contains?
I guess you could index it to solve this error, but it’s difficult to recommend the right approach without knowing what the tuple represents.

1 Like

Thanks for reply and sorry I forgot it, Actually I was working in colab, and probably the files are not saved immediately there, so t was not working then, After sometime,on reloading the page I got it. My model has returned two values ,the last layer before output was encoder layer, so I took the mean std dev and finally concatenated them, then these two values are passed through the final linear layer.