当使用对象检测API时,Matplotlib后端会转移到Agg

2024-04-20 10:54:42 发布

您现在位置:Python中文网/ 问答频道 /正文

在使用matplotlib和object detection API时,这个图没有显示出来,但是在我导入一些测试方法之前,它可以正常工作。在

我使用的是Anaconda虚拟环境、python3.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

到了最后一行时就会发生变化

^{2}$

之前,我可以给你看这个数字,比如plt.子批次(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_后端()”显示“Qt5Agg”。 但是在最后一行之后,这个数字没有弹出,虽然我确实从plt.子批次(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_后端(),它显示的是“Agg”,而不是前面的“Qt5Agg”。以及“表演()“引发错误:

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

环境有变化吗?在

最后一行的脚本可以找到here

非常感谢您的时间!在


Tags: fromimportapiobjectmatplotlibtensorflowasplt
1条回答
网友
1楼 · 发布于 2024-04-20 10:54:42

解决了。在~/models/research/object_detection/utils/visualization中找到了这条线_py实用工具公司名称:

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

只要评论一下就行了。在

相关问题 更多 >