I following the instructions here DeepLearning-LecNotes2 to run resnet34 on the dogbreeds dataset. When running these lines
log_preds,y = learn.TTA()
probs = np.exp(log_preds)
accuracy(log_preds,y), metrics.log_loss(y, probs)
I get a dimensions error when the last two functions are called.Should this be happening? I could reshape my probs data to the same dimension of the y variable, but how could I call the TTA function so that I would not have to do this. Can anyone give an explaination of what exactly learn.TTA() does?
The error I get is this:
TypeError Traceback (most recent call last)
in ()
----> 1 accuracy(log_preds,y), metrics.log_loss(y, probs)
2
Your error is because the accuracy function expects torch Tensors and your preds are a np array. You’ll want to call torch.from_numpy(preds).cuda(), that should fix it.
I’m having the same issue as the OP but haven’t managed to find a working solution yet from following the help here. I had the same original error and have now tried changing to
TypeError: eq received an invalid combination of arguments - got (numpy.ndarray), but expected one of:
* (int value)
didn't match because some of the arguments have invalid types: (numpy.ndarray)
* (torch.LongTensor other)
didn't match because some of the arguments have invalid types: (numpy.ndarray)
I too had this problem so searched through the forums. TTA() was changed in November 2017 because it had been averaging the log, rather than the probabilities. Now it returns the actual individual TTA predictions, which then have to be averaged. I think accuracy() has also changed. This gives the accuracy:
How did you go about finding this? I’m curious to see how I can hunt down the next similar problem I encounter. But your solution worked perfectly. Cheers!