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