Mmdetection框架中出现 RuntimeError(‘Invalid DISPLAY variable‘)

Mmdetection RuntimeError(‘Invalid DISPLAY variable’)

from mmdet.apis import init_detector, inference_detector
import mmcv

# Specify the path to model config and checkpoint file
config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'

# build the model from a config file and a checkpoint file
model = init_detector(config_file, checkpoint_file, device='cuda:0')

# test a single image and show the results
img = 'test.jpg'  # or img = mmcv.imread(img), which will only load it once
result = inference_detector(model, img)
# visualize the results in a new window
#model.show_result(img, result)
# or save the visualization results to image files
model.show_result(img, result, out_file='result.jpg')

Traceback (most recent call last):
  File "1.py", line 34, in <module>
    img2 = show_result_pyplot(model, img, result, score_thr=0.8)
  File "1.py", line 18, in show_result_pyplot
    img = model.show_result(img, result, score_thr=score_thr, show=False)
  File "/root/anaconda3/lib/python3.6/site-packages/mmdet-2.19.0-py3.6.egg/mmdet/models/detectors/base.py", line 353, in show_result
    out_file=out_file)
  File "/root/anaconda3/lib/python3.6/site-packages/mmdet-2.19.0-py3.6.egg/mmdet/core/visualization/image.py", line 119, in imshow_det_bboxes
    fig = plt.figure(win_name, frameon=False)
  File "/root/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py", line 548, in figure
    **kwargs)
  File "/root/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 161, in new_figure_manager
    return cls.new_figure_manager_given_figure(num, fig)
  File "/root/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 167, in new_figure_manager_given_figure
    canvas = cls.FigureCanvas(figure)
  File "/root/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5agg.py", line 24, in __init__
    super(FigureCanvasQTAgg, self).__init__(figure=figure)
  File "/root/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py", line 234, in __init__
    _create_qApp()
  File "/root/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py", line 125, in _create_qApp
    raise RuntimeError('Invalid DISPLAY variable')
RuntimeError: Invalid DISPLAY variable

问题原因

matplotlib 在 windows 下的默认 backend 是 TkAgg;在 Linux 下的默认 backend 是 Qt5Agg。但是这两个 backend 都要求有 GUI 图形界面,所以在 Linux 服务器上运行时会报错。

解决方案

vi  mmdet/core/visualization/image.py
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
cd mmdetection
python setup.py develop  #修改参数和代码需要重新编译
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值