mxnet
mxnet copied to clipboard
Train Neural Network Python Tutorial - Plot Images code not working
Description
I was not able to get images to plot in Train the neural network Python tutorial found here as the tutorial is written. Some solutions are proposed below.
Environment info (Required)
I ran the recommended script but no environment information was returned after the Environment heading. Working on a MacBook Pro.
Package used (Python/R/Scala/Julia): ----------Python Info---------- Version : 3.7.3 Compiler : Clang 4.0.1 (tags/RELEASE_401/final) Build : ('default', 'Mar 27 2019 16:54:48') Arch : ('64bit', '')
Steps to reproduce
(Paste the commands you ran that produced the error.)
- Follow the commands found in this tutorial .
- enter code found in code box 3 one line at a time. The issue comes up for me when entering the line
display.set_matplotlib_formats('svg')
. The terminal changes mode after entering this command, and variables defines in previous commands are no longer accessible. - even when omitting the line above, I get the error about plt not being defined (see solution below).
What have you tried to solve it?
- to resolve the error message about
plt
not being defined I had to includefrom matplotlib import pyplot as plt
- I omitted the line
display.set_matplotlib_formats('svg')
from code block 3
Note: the same issue may arise in this tutorial as there are similar commands here: http://mxnet.incubator.apache.org/api/python/docs/tutorials/getting-started/crash-course/5-predict.html
Hey, this is the MXNet Label Bot. Thank you for submitting the issue! I will try and suggest some labels so that the appropriate MXNet community members can help resolve it. Here are my recommended label(s): Example
@mxnet-label-bot , add [Bug, Example, Documentation]
It seems that this issue has been resolved in a notebook environment. The tutorial now includes import matplotlib.pyplot as plt
to solve the issue with plt
not being defined. Additionally, the 3rd code cell, when run in its entirety, functions as expected, displaying the images to the notebook, while still saving the variables from previous cells.
From my understanding, this tutorial was intended to be run in a notebook environment (i.e. Jupyter notebook), not directly from the terminal. Notebook environments like Jupyter and Jupyterlab work well for rendering images, markdown, LaTeX, etc., and were likely intended for this tutorial, given that it was written in markdown.
It is important to note that there is still the DeprecationWarning
(see first image above), suggesting that display.set_matplotlib_formats
is deprecated and that matplotlib_inline.backend_inline.set_matplotlib_formats()
should be used instead. Adding the following code block to the top of the 3rd cell and removing the line referenced in the main issue will resolve the warning (see accepted answer here for more details (https://stackoverflow.com/questions/36622237/jupyter-notebook-inline-plots-as-svg):
%matplotlib inline
import matplotlib_inline
matplotlib_inline.backend_inline.set_matplotlib_formats('svg')
I'd be happy to make the above changes to remove the warning if that would be helpful.
*Note: this fix requires a notebook environment since it uses the %matplotlib inline
built-in magic command for Jupyter. This will not work in a terminal environment. If you would like to have this work in a terminal environment, the suggestion from @TEChopra1000 to remove the line display.set_matplotlib_formats('svg')
still solves the issue in that context. Hope this helps!