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


(Muralidharan Surendran) #1

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


(RobG) #2

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


Dog Breed Identification challenge
(Muralidharan Surendran) #3

@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


(Alessa Bandrabur) #4

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()


(Muralidharan Surendran) #5

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


(Alessa Bandrabur) #6

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


(Muralidharan Surendran) #7

Yes I did but still get the error.


(Alessa Bandrabur) #8

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)**

(Gene K) #9

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.


(Muralidharan Surendran) #10

@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.


(Ivan Oboth) #11

Thanks abunch, this worked…