From ab7270ab8848f84df01e8c69480b267e21f67709 Mon Sep 17 00:00:00 2001 From: psomers3 Date: Thu, 17 Jun 2021 10:10:50 +0200 Subject: [PATCH] added error catch for visualization of coco images --- labelme/widgets/segmentation_macro.py | 41 ++++++++++++++------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/labelme/widgets/segmentation_macro.py b/labelme/widgets/segmentation_macro.py index bf7f4c17a..31b2df360 100644 --- a/labelme/widgets/segmentation_macro.py +++ b/labelme/widgets/segmentation_macro.py @@ -393,25 +393,28 @@ def do_instance_segmentation_coco(self): ) if not noviz: - 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) + try: + 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) + except ValueError as e: + print(f'Failed to create visualization for {base}.jpg') with open(out_ann_file, "w") as f: json.dump(data, f)