瀏覽代碼

Remove dependency on six and scipy

Kentaro Wada 7 年之前
父節點
當前提交
512d9affe7
共有 3 個文件被更改,包括 9 次插入8 次删除
  1. 5 3
      labelme/labelFile.py
  2. 3 3
      labelme/utils.py
  3. 1 2
      setup.py

+ 5 - 3
labelme/labelFile.py

@@ -20,8 +20,10 @@
 from base64 import b64encode, b64decode
 import json
 import os.path
+import sys
 
-import six
+
+PY2 = sys.version_info[0] == 2
 
 
 class LabelFileError(Exception):
@@ -39,7 +41,7 @@ class LabelFile(object):
 
     def load(self, filename):
         try:
-            with open(filename, 'rb' if six.PY2 else 'r') as f:
+            with open(filename, 'rb' if PY2 else 'r') as f:
                 data = json.load(f)
                 imagePath = data['imagePath']
                 imageData = b64decode(data['imageData'])
@@ -66,7 +68,7 @@ class LabelFile(object):
             imageData=b64encode(imageData).decode('utf-8'),
         )
         try:
-            with open(filename, 'wb' if six.PY2 else 'w') as f:
+            with open(filename, 'wb' if PY2 else 'w') as f:
                 json.dump(data, f, ensure_ascii=True, indent=2)
         except Exception as e:
             raise LabelFileError(e)

+ 3 - 3
labelme/utils.py

@@ -9,7 +9,6 @@ import matplotlib.pyplot as plt
 import numpy as np
 import PIL.Image
 import PIL.ImageDraw
-import scipy.misc
 
 
 def label_colormap(N=256):
@@ -104,8 +103,9 @@ def draw_label(label, img, label_names, colormap=None):
     plt.cla()
     plt.close()
 
-    out = np.array(PIL.Image.open(f))[:, :, :3]
-    out = scipy.misc.imresize(out, img.shape[:2])
+    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)
     return out
 
 

+ 1 - 2
setup.py

@@ -17,9 +17,8 @@ version = '2.6.4'
 
 install_requires = [
     'matplotlib',
+    'numpy',
     'Pillow>=2.8.0',
-    'scipy',
-    'six',
     'PyYAML',
 ]