Prechádzať zdrojové kódy

Use plt.switch_backend

https://github.com/matplotlib/matplotlib/issues/3466#issuecomment-270603717
Kentaro Wada 7 rokov pred
rodič
commit
803aec5efc
2 zmenil súbory, kde vykonal 5 pridanie a 3 odobranie
  1. 0 3
      labelme/cli/json_to_dataset.py
  2. 5 0
      labelme/utils.py

+ 0 - 3
labelme/cli/json_to_dataset.py

@@ -4,9 +4,6 @@ import os
 import os.path as osp
 import warnings
 
-import matplotlib
-matplotlib.use('Agg')
-
 import numpy as np
 import PIL.Image
 import yaml

+ 5 - 0
labelme/utils.py

@@ -76,6 +76,9 @@ def polygons_to_mask(img_shape, polygons):
 
 
 def draw_label(label, img, label_names, colormap=None):
+    backend_org = plt.rcParams['backend']
+    plt.switch_backend('agg')
+
     plt.subplots_adjust(left=0, right=1, top=1, bottom=0,
                         wspace=0, hspace=0)
     plt.margins(0, 0)
@@ -103,6 +106,8 @@ def draw_label(label, img, label_names, colormap=None):
     plt.cla()
     plt.close()
 
+    plt.switch_backend(backend_org)
+
     out_size = (img.shape[1], img.shape[0])
     out = PIL.Image.open(f).resize(out_size, PIL.Image.BILINEAR).convert('RGB')
     out = np.asarray(out)