From 9085123e560fc829bdda37313f75be41bdb5bec6 Mon Sep 17 00:00:00 2001 From: Kentaro Wada Date: Thu, 13 Jun 2024 17:45:20 +0900 Subject: [PATCH] Save mask as uint8 for better compatibility with other tools --- labelme/app.py | 5 ++++- labelme/label_file.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/labelme/app.py b/labelme/app.py index 35938fae0..8f194aa86 100644 --- a/labelme/app.py +++ b/labelme/app.py @@ -10,6 +10,7 @@ import imgviz import natsort +import numpy as np from qtpy import QtCore from qtpy import QtGui from qtpy import QtWidgets @@ -1303,7 +1304,9 @@ def format_shape(s): description=s.description, shape_type=s.shape_type, flags=s.flags, - mask=None if s.mask is None else utils.img_arr_to_b64(s.mask), + mask=None + if s.mask is None + else utils.img_arr_to_b64(s.mask.astype(np.uint8)), ) ) return data diff --git a/labelme/label_file.py b/labelme/label_file.py index bffee8af3..3c1f31530 100644 --- a/labelme/label_file.py +++ b/labelme/label_file.py @@ -111,7 +111,9 @@ def load(self, filename): flags=s.get("flags", {}), description=s.get("description"), group_id=s.get("group_id"), - mask=utils.img_b64_to_arr(s["mask"]) if s.get("mask") else None, + mask=utils.img_b64_to_arr(s["mask"]).astype(bool) + if s.get("mask") + else None, other_data={k: v for k, v in s.items() if k not in shape_keys}, ) for s in data["shapes"]