版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
Jupyter notebook 运行 tensorflow报告以下错误:
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
参考stackoverflow解决:
https://stackoverflow.com/questions/3285193/how-to-switch-backends-in-matplotlib-python
其中的代码用来检测可用的agg环境:
import matplotlib
gui_env = [i for i in matplotlib.rcsetup.interactive_bk]
non_gui_backends = matplotlib.rcsetup.non_interactive_bk
print ("Non Gui backends are:", non_gui_backends)
print ("Gui backends I will test for", gui_env)
for gui in gui_env:
print ("testing", gui)
try:
matplotlib.use(gui,warn=False, force=True)
from matplotlib import pyplot as plt
print (" ",gui, "Is Available")
plt.plot([1.5,2.0,2.5])
fig = plt.gcf()
fig.suptitle(gui)
plt.show()
print ("Using ..... ",matplotlib.get_backend())
except:
print (" ",gui, "Not found")
立刻会弹出如下的图片:
说明在本机有Qt5Agg可用,所以修改原代码为:
import numpy as np
import os
import tensorflow as tf
import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib import pyplot as plt
from PIL import Image
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
注意其中的第4行和第5行为新添加的。
参考环境:
Windows 7 7601 sp1,
Tensorflow1.10.0,
扫描二维码关注公众号,回复:
7652323 查看本文章
Jupyter notebook server is: 5.7.8
Python 3.6.8
<end>