Lesson 2 Dog Breeds Error on call of accuracy(log_preds,y)

Hi,
When invoking the accuracy method from the below lines of code.

> log_preds,y = learn.TTA()
> probs = np.exp(log_preds)
> accuracy(log_preds,y), metrics.log_loss(y, probs)

I get the below error

TypeError: torch.max received an invalid combination of arguments - got (numpy.ndarray, dim=int), but expected one of:
** * (torch.FloatTensor source)**
** * (torch.FloatTensor source, torch.FloatTensor other)**
** didn’t match because some of the keywords were incorrect: dim**
** * (torch.FloatTensor source, int dim)**
** * (torch.FloatTensor source, int dim, bool keepdim)**

I then searched and found the below post. However when I tried both accuracy_np method and

I get the below error
Attribute Error: ‘bool’ object has no attribute ‘mean’

Any solution to the above problem?

Regards
Murali

TTA used to return the average of the augmentations as a prediction. Now it returns the set so you can do with them as you please. Change it like this Planet Classification Challenge

@digitalspecialists that doesnt help. I alreasdy tried what is mentioned and I get the same error as highlighted in above
TypeError: torch.max received an invalid combination of arguments - got (numpy.ndarray, dim=int), but expected one of:
* (torch.FloatTensor source)
* (torch.FloatTensor source, torch.FloatTensor other)
didn’t match because some of the keywords were incorrect: dim
* (torch.FloatTensor source, int dim)
* (torch.FloatTensor source, int dim, bool keepdim)

@rachel @reshama @jeremy any idea what the error could and a potential solution to the same

There were some updates. Read more here

log_preds, y = learn.tta()
probs = np.mean(np.exp(log_preds), axis=0)

You may also want to consider to use accuracy_np() (which works with numpy arrays), not accuracy()

1 Like

@alessa I have tried using accuracy and accuracy_np and both dont work :frowning: I dont know whats wrong with, will dig deep

Did you try already with probs = np.mean(np.exp(log_preds), axis=0) instead of probs = np.exp(log_preds)

Yes I did but still get the error.

Is it the same error, or now you get something else

TypeError: torch.max received an invalid combination of arguments - got (numpy.ndarray, dim=int), but expected one of:
** * (torch.FloatTensor source)**
** * (torch.FloatTensor source, torch.FloatTensor other)**
** didn’t match because some of the keywords were incorrect: dim**
** * (torch.FloatTensor source, int dim)**
** * (torch.FloatTensor source, int dim, bool keepdim)**

Muralidharan, you should try the following and see what works:

  • make sure your metrics.py is up to date
  • restart your jupyter notebook kernel and run code up to the line previous to log_preds,y = learn.TTA()
  • use probs = np.mean(np.exp(log_preds), axis=0) along with accuracy_np(probs,y)

As someone who went through the same issue recently, I’m pretty sure this should work for you.

5 Likes

@wigl Thank you the source that you gave me worked. I restarted my paperspace instance and had the above code and it worked fine now.

2 Likes

Thanks abunch, this worked…

1 Like