Repository: PaddlePaddle/PaddleSeg

Issue:
在应用labelme2seg.py转化labelme生成的json过程，报错如下
在line 81,有判断语句：
            if lbl.min >= 0 and lbl.max() <= 255:
总是报错：‘tuple’ object has no attribute 'min'
看源码，不应该这样啊，请问是什么原因？





Discussion:
是的，lbl应该是numpy的数组，不应该是tuple。
你可以检查一下是否是line 72这个函数的输入不对导致的
`lbl = labelme.utils.shapes_to_label(
                img_shape=img.shape,
                shapes=data['shapes'],
                label_name_to_value=class_name_to_id,
            )`


Resolving patch:
diff --git a/pdseg/tools/jingling2seg.py b/pdseg/tools/jingling2seg.py
--- a/pdseg/tools/jingling2seg.py
+++ b/pdseg/tools/jingling2seg.py
@@ -17,10 +17,8 @@
 
 def parse_args():
     parser = argparse.ArgumentParser(
-        formatter_class=argparse.ArgumentDefaultsHelpFormatter
-    )
-    parser.add_argument('input_dir',
-                        help='input annotated directory')
+        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+    parser.add_argument('input_dir', help='input annotated directory')
     return parser.parse_args()
 
 
@@ -62,8 +60,7 @@ def main(args):
         print('Generating dataset from:', label_file)
         with open(label_file) as f:
             base = osp.splitext(osp.basename(label_file))[0]
-            out_png_file = osp.join(
-                output_dir, base + '.png')
+            out_png_file = osp.join(output_dir, base + '.png')
 
             data = json.load(f)
 
@@ -77,16 +74,22 @@ def main(args):
                         # convert jingling format to labelme format
                         points = []
                         for i in range(1, int(len(polygon) / 2) + 1):
-                            points.append([polygon['x' + str(i)], polygon['y' + str(i)]])
-                        shape = {'label': name, 'points': points, 'shape_type': 'polygon'}
+                            points.append(
+                                [polygon['x' + str(i)], polygon['y' + str(i)]])
+                        shape = {
+                            'label': name,
+                            'points': points,
+                            'shape_type': 'polygon'
+                        }
                         data_shapes.append(shape)
 
             if 'size' not in data:
                 continue
             data_size = data['size']
-            img_shape = (data_size['height'], data_size['width'], data_size['depth'])
+            img_shape = (data_size['height'], data_size['width'],
+                         data_size['depth'])
 
-            lbl = labelme.utils.shapes_to_label(
+            lbl, _ = labelme.utils.shapes_to_label(
                 img_shape=img_shape,
                 shapes=data_shapes,
                 label_name_to_value=class_name_to_id,
@@ -102,8 +105,7 @@ def main(args):
             else:
                 raise ValueError(
                     '[%s] Cannot save the pixel-wise class label as PNG. '
-                    'Please consider using the .npy format.' % out_png_file
-                )
+                    'Please consider using the .npy format.' % out_png_file)
 
 
 if __name__ == '__main__':
diff --git a/pdseg/tools/labelme2seg.py b/pdseg/tools/labelme2seg.py
--- a/pdseg/tools/labelme2seg.py
+++ b/pdseg/tools/labelme2seg.py
@@ -17,10 +17,8 @@
 
 def parse_args():
     parser = argparse.ArgumentParser(
-        formatter_class=argparse.ArgumentDefaultsHelpFormatter
-    )
-    parser.add_argument('input_dir',
-                        help='input annotated directory')
+        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+    parser.add_argument('input_dir', help='input annotated directory')
     return parser.parse_args()
 
 
@@ -61,15 +59,14 @@ def main(args):
         print('Generating dataset from:', label_file)
         with open(label_file) as f:
             base = osp.splitext(osp.basename(label_file))[0]
-            out_png_file = osp.join(
-                output_dir, base + '.png')
+            out_png_file = osp.join(output_dir, base + '.png')
 
             data = json.load(f)
 
             img_file = osp.join(osp.dirname(label_file), data['imagePath'])
             img = np.asarray(PIL.Image.open(img_file))
 
-            lbl = labelme.utils.shapes_to_label(
+            lbl, _ = labelme.utils.shapes_to_label(
                 img_shape=img.shape,
                 shapes=data['shapes'],
                 label_name_to_value=class_name_to_id,
@@ -85,8 +82,7 @@ def main(args):
             else:
                 raise ValueError(
                     '[%s] Cannot save the pixel-wise class label as PNG. '
-                    'Please consider using the .npy format.' % out_png_file
-                )
+                    'Please consider using the .npy format.' % out_png_file)
 
 
 if __name__ == '__main__':


Test patch: