Skip to content

Commit

Permalink
完善labelme2coco脚本.
Browse files Browse the repository at this point in the history
  • Loading branch information
yang committed Jun 13, 2022
1 parent 0de90d2 commit e86641c
Showing 1 changed file with 2 additions and 26 deletions.
28 changes: 2 additions & 26 deletions data/labelme2coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
sys.exit(1)


def labelme2coco(input_dir='', output_dir='', labels=[], train_val_split=0.8, noviz=False):
def labelme2coco(input_dir='', output_dir='', labels=[], train_val_split=0.8):

train_out_ann_file = osp.join(output_dir, "train_annotations.json")
val_out_ann_file = osp.join(output_dir, "val_annotations.json")
Expand Down Expand Up @@ -135,29 +135,6 @@ def labelme2coco(input_dir='', output_dir='', labels=[], train_val_split=0.8, no
)
)

if not noviz:
viz = img
if masks:
labels, captions, masks = zip(
*[
(class_name_to_id[cnm], cnm, msk)
for (cnm, gid), msk in masks.items()
if cnm in class_name_to_id
]
)
viz = imgviz.instances2rgb(
image=img,
labels=labels,
masks=masks,
captions=captions,
font_size=15,
line_width=2,
)
out_viz_file = osp.join(
output_dir, "Visualization", base + ".jpg"
)
imgviz.io.imsave(out_viz_file, viz)

with open(train_out_ann_file, "w") as f:
json.dump(train_dict, f)
with open(val_out_ann_file, "w") as f:
Expand All @@ -169,6 +146,5 @@ def labelme2coco(input_dir='', output_dir='', labels=[], train_val_split=0.8, no
input_dir='../../cat_dog_face_data/labels',
output_dir='../../cat_dog_face_data/coco_labels',
labels=['head'],
train_val_split=0.8,
noviz=True
train_val_split=0.8
)

0 comments on commit e86641c

Please sign in to comment.