Lesson1-vgg.ipynb fails on `accuracy(log_preds,y)`

The issue is that lesson1-vgg.ipynb (https://github.com/fastai/fastai/blob/master/courses/dl1/lesson1-vgg.ipynb) cannot be completed. I cannot run the last line, accuracy(log_preds,y), as it fails saying:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-18-826ab674d3ed> in <module>()
  1 log_preds,y = learn.TTA()
----> 2 accuracy(log_preds,y)

/media/user/drive/git_fastai/fastai/courses/dl1/fastai/metrics.py in accuracy(preds, targs)
  7 
  8 def accuracy(preds, targs):
----> 9     preds = torch.max(preds, dim=1)[1]
 10     return (preds==targs).float().mean()
 11 

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 have an updated version of fastai from git, running on an up-to-date Ubuntu desktop, with a git pull and conda env update as of today. I had previously last updated a couple of weeks ago, and tried updating today only because this wouldn’t work. Unfortunately, updating did not resolve the issue, which is why I am posting this.

(On a side note, for my understanding only, why does vgg16 take almost 4 gb of the gpu? running the regular lesson 1 doesn’t seem to need so much. ??)

Hi @fone: can you try: accuracy_np(log_preds, y)?

Can you try data.is_multi and let us know if you get True/False? I was getting this error when data.is_multi was True

For speed reasons I am using:

PATH = "data/dogscats/sample"
sz=224
arch=vgg16
bs=24

@HungDO

Running:

accuracy_np(log_preds, y)

Returns:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-21-0c7a3661244b> in <module>()
----> 1 accuracy_np(log_preds, y)

/media/user/drive/git_fastai/fastai/courses/dl1/fastai/metrics.py in accuracy_np(preds, targs)
      4 def accuracy_np(preds, targs):
      5     preds = np.argmax(preds, 1)
----> 6     return (preds==targs).mean()
      7 
      8 def accuracy(preds, targs):

AttributeError: 'bool' object has no attribute 'mean'

@EpiphanyMania

Running:

data.is_multi

Returns:

False

@fone,

probs = np.mean(np.exp(log_preds),0)
accuracy_np(probs, y)

The reason you have to apply np.exp to log_preds since the output of learn.TTA() are the logarithm of the probabilites. And you have to applied np.mean because of TTA (test time argumentation).

Hope that help.