Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to use Matlab CNN Resnet50 pre-trained model to convert ONNX to use in Pytorch #52

Open
icui4cu0118 opened this issue Aug 23, 2022 · 0 comments

Comments

@icui4cu0118
Copy link

icui4cu0118 commented Aug 23, 2022

I first use onnx2pytorch to convert onnx to pytorch, and then use it to use the test set to get the accuracy.
This is my part of code :

model = torch.load(" .pkl")
model.eval()
for epoch in range(1) :
    testing_loss = 0.0
    testing_correct = 0.0
    zpred, ztrue = [], []
    for test_inputs, test_labels in test_data :
        test_inputs, test_labels = test_inputs.to(device), test_labels.to(device)
        output = model(test_inputs)    #error poit
        loss = criterion(output, test_labels)
        _, pred = torch.max(output.data, 1)
        testing_loss += loss.item() 
        testing_correct += torch.sum(pred == test_labels.data)
        output = (torch.max(torch.exp(output), 1)[1]).data.cpu().numpy()
        zpred.extend(output)
        testlabel = test_labels.data.cpu().numpy()
        ztrue.extend(testlabel)
    test_loss = testing_loss / len(test_loader)
    test_acc = 100 * testing_correct.cpu().numpy() / len(test_loader)

    print('Epoch is : {}, Test Loss is : {:.4f} Test Accuracy is :{:.4f}%'.format(epoch + 1, test_loss, test_acc))

But I got this error :

sum() received an invalid combination of arguments - got (Tensor, Tensor), but expected one of :
 * (Tensor input, *, torch.dtype dtype)
 * (Tensor input, tuple of ints dim, bool keepdim, *, torch.dtype dtype, Tensor out)
 * (Tensor input, tuple of names dim, bool keepdim, *, torch.dtype dtype, Tensor out)

How can I change the second tensor to the expected attribute?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant