Show_batch() and show_results() do not show anything

I am trying to follow this tutorial: Computer vision | fastai

Everything works, except for dls.show_batch() and learn.show_results() do not show anything at all in Jupyter Notebook.

Note that in these screenshots, I am using Jupyter Notebook in VS Code with its python extensions. But I did try with just vanilla Jupyter Notebook (by runningjupyter notebook --no-browser) and these two methods do not show anything either. So I think this is not a VS Code issue.

I am using fastai v2 installed by conda install -c fastchan fastai.

Do I make some mistake? Anyone know how to make them work? Thanks.

Try running %matplotlib inline at the top of the notebook.

1 Like

This works perfectly! Thanks!
Could you explain a bit more about what the syntax is and what it does? Thanks.

Thanks.

Well that command option (--no-browser) is just to tell it to not automatically open a browser, because the program is running in a Linux environment with no GUI (WSL2). I still need to copy the URL and open it in a browser and see the Jupyter Notebook. It is the original Jupyter Notebook indeed.

Also VS Code is not a “text” oriented environment. It is Electron - essentially a browser. And it can display ipywidgets such as iprogress that fastai uses.

In Jupyter and IPython, anything starting with % is a line magic. If there is %%, then it’s a cell magic. They are convenience commands to do common tasks. In this example it’s setting the matplotlib backend to be inline, or in line with the other inputs and outputs. A matplotlib backend is where the graph is rendered, for example the notebook, a pdf, an svg, or a jpeg.

1 Like

AttributeError Traceback (most recent call last)
Cell In[53], line 1
----> 1 do_fit(‘v1.1’, slice(lr*10))

Cell In[52], line 4, in do_fit(save_name, lrs, pct_start)
2 learn.fit_one_cycle(1, lrs, pct_start=pct_start)
3 learn.save(save_name)
----> 4 learn.show_results()

File /fastai/basic_train.py:407, in Learner.show_results(self, ds_type, rows, **kwargs)
405 preds = self.pred_batch(ds_type)
406 *self.callbacks,rec_cpu = self.callbacks
→ 407 x,y = rec_cpu.input,rec_cpu.target
408 norm = getattr(self.data,‘norm’,False)
409 if norm:

AttributeError: ‘RecordOnCPU’ object has no attribute ‘input’