17
17
18
18
def parse_args ():
19
19
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' )
24
22
return parser .parse_args ()
25
23
26
24
@@ -62,8 +60,7 @@ def main(args):
62
60
print ('Generating dataset from:' , label_file )
63
61
with open (label_file ) as f :
64
62
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' )
67
64
68
65
data = json .load (f )
69
66
@@ -77,16 +74,22 @@ def main(args):
77
74
# convert jingling format to labelme format
78
75
points = []
79
76
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
+ }
82
84
data_shapes .append (shape )
83
85
84
86
if 'size' not in data :
85
87
continue
86
88
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' ])
88
91
89
- lbl = labelme .utils .shapes_to_label (
92
+ lbl , _ = labelme .utils .shapes_to_label (
90
93
img_shape = img_shape ,
91
94
shapes = data_shapes ,
92
95
label_name_to_value = class_name_to_id ,
@@ -102,8 +105,7 @@ def main(args):
102
105
else :
103
106
raise ValueError (
104
107
'[%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 )
107
109
108
110
109
111
if __name__ == '__main__' :
0 commit comments