Matplotlib后端在使用对象检测API时移动,QtAgg到Agg



将matplotlib与对象检测API一起使用时,该图没有显示,但是在我导入一些测试方法之前,它工作正常。

我正在使用Anaconda虚拟环境,python 3.6和google对象检测API。

import matplotlib.pyplot as plt
import tensorflow as tf
from matplotlib import patches
from object_detection.anchor_generators.multiple_grid_anchor_generator import create_ssd_anchors
from object_detection.models.ssd_mobilenet_v2_feature_extractor_test import SsdMobilenetV2FeatureExtractorTest
from object_detection.models.ssd_mobilenet_v2_feature_extractor_test import SsdMobilenetV2FeatureExtractorTest

当涉及到最后一行时,就会发生变化

from object_detection.models.ssd_mobilenet_v2_feature_extractor_test import SsdMobilenetV2FeatureExtractorTest"

之前,我可以显示图形,例如 plt.subplot(2,2(,我弹出图形并执行以下操作:

(<Figure size 640x480 with 4 Axes>,
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x7f4615eb8ba8>,
     <matplotlib.axes._subplots.AxesSubplot object at 0x7f4614d320f0>],
    [<matplotlib.axes._subplots.AxesSubplot object at 0x7f4614ce36a0>,
     <matplotlib.axes._subplots.AxesSubplot object at 0x7f4614c92c50>]],
   dtype=object))
WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
  * https://github.com/tensorflow/addons

如果您依赖于此处未列出的功能,请提交问题。

"plt.get_backend(("显示"Qt5Agg"。但是在最后一行之后,该图没有弹出,尽管我确实从"plt.subplots(2,2("中得到了结果:

(<Figure size 640x480 with 4 Axes>,
 array([[<matplotlib.axes._subplots.AxesSubplot object at 0x7f460b8a5f60>,
     <matplotlib.axes._subplots.AxesSubplot object at 0x7f460b86b5c0>],
    [<matplotlib.axes._subplots.AxesSubplot object at 0x7f460a7b2fd0>,
     <matplotlib.axes._subplots.AxesSubplot object at 0x7f460a7cb630>]],
   dtype=object))

现在,当我键入"plt.get_backend(("时,它显示"Agg",而不是之前的"Qt5Agg"。 和 "plt.show((" 抛出错误:

UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
  #!/usr/bin/env python2

我使用的口译员是

~/anaconda3/envs/py36/bin/python

这里的环境有变化吗?

最后一行的脚本可以在这里找到

非常感谢您的时间!

已解决。在~/models/research/object_detecion/utils/visualization_utils.py中找到了这一行:

import matplotlib; matplotlib.use('Agg')  # pylint: disable=multiple-statements

只需评论它并且工作正常。

已解决。我正在虚拟环境上本地运行,并尝试了几种建议的解决方案,但没有成功。我尝试了方云飞上面的建议,但后来意识到,注释掉~/models/research/object_detecion/utils/visualization_utils.py文件夹中import matplotlib; matplotlib.use('Agg') 的代码行是不够的。我通过将这段代码放在脚本的正文中发现了:print('matplotlib backend= ',matplotlib.get_backend())因为这仍然返回"agg",所以我不得不在脚本的导入部分末尾添加此matplotlib.use('MacOSX')。我正在MacBook Pro上运行macOS Big Sur

最新更新