0
votes

I am trying to run a image classification on Google Cloud Engine VM (via SSH login) model and trying to plot a graph for accuracy and loss. Model is running fine but getting error for graph plot. Below is code and error message.

Can anyone have idea how to fix this error in SSH Virtual Machine?

Tried 'tkagg' for matplotlib backend, but still getting the error.

Graph Code

import matplotlib  matplotlib.use('tkagg')
import matplotlib.pyplot as plt

plot the training loss and accuracy

fig = plt.figure() plt.style.use("ggplot") plt.plot(np.arange(0, 10),
    H.history["loss"], label="train_loss") plt.plot(np.arange(0, 10), 
    H.history["val_loss"], label="val_loss") plt.plot(np.arange(0, 10),
    H.history["acc"], label="train_acc") plt.plot(np.arange(0, 10),
    H.history["val_acc"], label="val_acc") plt.title("Training Loss and Accuracy") 
    plt.xlabel("Epoch #") 
    plt.ylabel("Loss/Accuracy") 
    plt.legend() 
    plt.savefig('without_aug.png', dpi = fig.dpi, bbox_inches = 'tight')

Error:

Traceback (most recent call last):
File "minivggnet_flowers17.py", line 73, in
fig = plt.figure()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 533, in figure
**kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 161, in new_figure_manager
return cls.new_figure_manager_given_figure(num, fig)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/_backend_tk.py", line 1046, in new_figure_manager_given_figure
window = Tk.Tk(className="matplotlib")
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1823, in init
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

Can anyone have idea how to fix this error in SSH Virtual Machine?

1
Welcome to SO; please do spend a minute to see how to properly format your code blocks (done it for you this time. Also, question has nothing to do with deep-learning - kindly do not spam irrelevant tags (removed). - desertnaut
Thank you @desertnaut. Will keep the code blocks properly from next time. - AbhinayReddy Yarva

1 Answers

0
votes

You can use jupiter lab for visualization and running codes line by line.In the cloud VM you need to install jupyter lab using pip - pip install jupyterlab and then start the jupyter lab server by typing this command in terminal -

jupyter lab --ip=0.0.0.0 --port=9090 use the link provided by the output of this command to paste it on your web browser to open jupyter notebook. here you can run matplotlib imshow function for visualization.

Note :- port no can be anything but must be open to access from over the internet. you need to check google cloud VM network setting to add port no for global users or make it public.