Skip to content

Commit a7ba98a

Browse files
authored
Fix label tools bug (#224)
1 parent cd51ed6 commit a7ba98a

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

pdseg/tools/jingling2seg.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717

1818
def parse_args():
1919
parser = argparse.ArgumentParser(
20-
formatter_class=argparse.ArgumentDefaultsHelpFormatter
21-
)
22-
parser.add_argument('input_dir',
23-
help='input annotated directory')
20+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
21+
parser.add_argument('input_dir', help='input annotated directory')
2422
return parser.parse_args()
2523

2624

@@ -62,8 +60,7 @@ def main(args):
6260
print('Generating dataset from:', label_file)
6361
with open(label_file) as f:
6462
base = osp.splitext(osp.basename(label_file))[0]
65-
out_png_file = osp.join(
66-
output_dir, base + '.png')
63+
out_png_file = osp.join(output_dir, base + '.png')
6764

6865
data = json.load(f)
6966

@@ -77,16 +74,22 @@ def main(args):
7774
# convert jingling format to labelme format
7875
points = []
7976
for i in range(1, int(len(polygon) / 2) + 1):
80-
points.append([polygon['x' + str(i)], polygon['y' + str(i)]])
81-
shape = {'label': name, 'points': points, 'shape_type': 'polygon'}
77+
points.append(
78+
[polygon['x' + str(i)], polygon['y' + str(i)]])
79+
shape = {
80+
'label': name,
81+
'points': points,
82+
'shape_type': 'polygon'
83+
}
8284
data_shapes.append(shape)
8385

8486
if 'size' not in data:
8587
continue
8688
data_size = data['size']
87-
img_shape = (data_size['height'], data_size['width'], data_size['depth'])
89+
img_shape = (data_size['height'], data_size['width'],
90+
data_size['depth'])
8891

89-
lbl = labelme.utils.shapes_to_label(
92+
lbl, _ = labelme.utils.shapes_to_label(
9093
img_shape=img_shape,
9194
shapes=data_shapes,
9295
label_name_to_value=class_name_to_id,
@@ -102,8 +105,7 @@ def main(args):
102105
else:
103106
raise ValueError(
104107
'[%s] Cannot save the pixel-wise class label as PNG. '
105-
'Please consider using the .npy format.' % out_png_file
106-
)
108+
'Please consider using the .npy format.' % out_png_file)
107109

108110

109111
if __name__ == '__main__':

pdseg/tools/labelme2seg.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717

1818
def parse_args():
1919
parser = argparse.ArgumentParser(
20-
formatter_class=argparse.ArgumentDefaultsHelpFormatter
21-
)
22-
parser.add_argument('input_dir',
23-
help='input annotated directory')
20+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
21+
parser.add_argument('input_dir', help='input annotated directory')
2422
return parser.parse_args()
2523

2624

@@ -61,15 +59,14 @@ def main(args):
6159
print('Generating dataset from:', label_file)
6260
with open(label_file) as f:
6361
base = osp.splitext(osp.basename(label_file))[0]
64-
out_png_file = osp.join(
65-
output_dir, base + '.png')
62+
out_png_file = osp.join(output_dir, base + '.png')
6663

6764
data = json.load(f)
6865

6966
img_file = osp.join(osp.dirname(label_file), data['imagePath'])
7067
img = np.asarray(PIL.Image.open(img_file))
7168

72-
lbl = labelme.utils.shapes_to_label(
69+
lbl, _ = labelme.utils.shapes_to_label(
7370
img_shape=img.shape,
7471
shapes=data['shapes'],
7572
label_name_to_value=class_name_to_id,
@@ -85,8 +82,7 @@ def main(args):
8582
else:
8683
raise ValueError(
8784
'[%s] Cannot save the pixel-wise class label as PNG. '
88-
'Please consider using the .npy format.' % out_png_file
89-
)
85+
'Please consider using the .npy format.' % out_png_file)
9086

9187

9288
if __name__ == '__main__':

0 commit comments

Comments
 (0)