Skip to content

Commit

Permalink
Use npy in labelme2voc.py for -1 value in labels
Browse files Browse the repository at this point in the history
PNG does not keep negative values.
  • Loading branch information
wkentaro committed Jun 13, 2018
1 parent dd75c66 commit a386eea
Show file tree
Hide file tree
Showing 25 changed files with 7 additions and 7 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions examples/instance_segmentation/labelme2voc.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ def main():
out_img_file = osp.join(
args.out_dir, 'JPEGImages', base + '.jpg')
out_cls_file = osp.join(
args.out_dir, 'SegmentationClass', base + '.png')
args.out_dir, 'SegmentationClass', base + '.npy')
out_clsv_file = osp.join(
args.out_dir, 'SegmentationClassVisualization', base + '.jpg')
out_ins_file = osp.join(
args.out_dir, 'SegmentationObject', base + '.png')
args.out_dir, 'SegmentationObject', base + '.npy')
out_insv_file = osp.join(
args.out_dir, 'SegmentationObjectVisualization', base + '.jpg')

Expand All @@ -81,15 +81,16 @@ def main():
label_name_to_value=class_name_to_id,
type='instance',
)
ins[cls == -1] = 0 # ignore it.

PIL.Image.fromarray(cls).save(out_cls_file)
np.save(out_cls_file, cls)
label_names = ['%d: %s' % (cls_id, cls_name)
for cls_id, cls_name in enumerate(class_names)]
clsv = labelme.utils.draw_label(
cls, img, label_names, colormap=colormap)
PIL.Image.fromarray(clsv).save(out_clsv_file)

PIL.Image.fromarray(ins).save(out_ins_file)
np.save(out_ins_file, ins)
instance_ids = np.unique(ins)
instance_names = [str(i) for i in range(max(instance_ids) + 1)]
insv = labelme.utils.draw_label(
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions examples/semantic_segmentation/labelme2voc.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def main():
out_img_file = osp.join(
args.out_dir, 'JPEGImages', base + '.jpg')
out_lbl_file = osp.join(
args.out_dir, 'SegmentationClass', base + '.png')
args.out_dir, 'SegmentationClass', base + '.npy')
out_viz_file = osp.join(
args.out_dir, 'SegmentationClassVisualization', base + '.jpg')

Expand All @@ -75,11 +75,10 @@ def main():
label_name_to_value=class_name_to_id,
)

lbl_pil = PIL.Image.fromarray(lbl)
# Only works with uint8 label
# lbl_pil = PIL.Image.fromarray(lbl, mode='P')
# lbl_pil.putpalette((colormap * 255).flatten())
lbl_pil.save(out_lbl_file)
np.save(out_lbl_file, lbl)

label_names = ['%d: %s' % (cls_id, cls_name)
for cls_id, cls_name in enumerate(class_names)]
Expand Down

0 comments on commit a386eea

Please sign in to comment.