Windows环境Tensorflow中plt.show()不显示图像的问题

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

说明在本机有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,

Jupyter notebook server is: 5.7.8

Python 3.6.8

<end>

 

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值