Lesson 1 trains OK, but plotting gives valueerror on axes of array

Hello all,

I am trying to get lesson 1 to run (“Image classification with Convolutional Neural Networks”). I am able to train the model (i think) but when I get to the graphs and most_cat-like etc, it then starts failing.

For example, the instruction box:

# 1. A few correct labels at random
plot_val_with_title(rand_by_correct(True), "Correctly classified")

Results in the following output:

Correctly classified

ValueError                                Traceback (most recent call last)
<ipython-input-57-d7a653989880> in <module>()
      1 # 1. A few correct labels at random
----> 2 plot_val_with_title(rand_by_correct(True), "Correctly classified")

<ipython-input-45-0f6ae40ca2b7> in plot_val_with_title(idxs, title)
      5     title_probs = [probs[x] for x in idxs]
      6     print(title)
----> 7     return plots(imgs, rows=1, titles=title_probs, figsize=(16,8))

~/Documents/fastai/fastai/courses/dl1/fastai/plots.py in plots(ims, figsize, rows, interp, titles, maintitle)
      9     if type(ims[0]) is np.ndarray:
     10         ims = np.array(ims)
---> 11         if (ims.shape[-1] != 3): ims = ims.transpose((0,2,3,1))
     12     f = plt.figure(figsize=figsize)
     13     if maintitle is not None:

ValueError: axes don't match array

However, nothing past this seems to work.

Note that trainning does give an error about javascript, but I thought this was all python based.

data = ImageClassifierData.from_paths(PATH, tfms=tfms_from_model(arch, sz))
learn = ConvLearner.pretrained(arch, data, precompute=True)
learn.fit(0.01, 3)


Widget Javascript not detected.  It may not be installed or enabled properly.

Error rendering Jupyter widget. Widget not found: {"model_id":"ab8447004e2e4fbc9b99cac46d0c3bdc"}

[ 0.       0.04573  0.0266   0.99121]                           
[ 1.       0.03284  0.02791  0.99023]                         
[ 2.       0.03425  0.02573  0.99072]                   

Thank you for any and all help!

Can you please check if the notebooks are updated properly. Actually, in the Dogs vs cats competition, Jeremy uses a different Plots method compared to one in the library.

Plots in Lesson 1

def plots(ims, figsize=(12,6), rows=1, titles=None):
    f = plt.figure(figsize=figsize)
    for i in range(len(ims)):
        sp = f.add_subplot(rows, len(ims)//rows, i+1)
        if titles is not None: sp.set_title(titles[i], fontsize=16)

Plots in Plots.py

def plots(ims, figsize=(12,6), rows=1, interp=False, titles=None, maintitle=None):
if type(ims[0]) is np.ndarray:
ims = np.array(ims)
if (ims.shape[-1] != 3): ims = ims.transpose((0,2,3,1))
f = plt.figure(figsize=figsize)
if maintitle is not None:
plt.suptitle(maintitle, fontsize=16)
for i in range(len(ims)):
sp = f.add_subplot(rows, ceildiv(len(ims), rows), i+1)
if titles is not None: sp.set_title(titles[i], fontsize=16)
plt.imshow(ims[i], interpolation=None if interp else ‘none’)

High chance that you would have forgotten to run that cell in lesson 1. Try running it again.

But basic difference was Plots.py method takes only three images . Not sure of the reason . @jeremy can help here to understand the same.


Save my day