Skip to content

Commit

Permalink
Save mask as uint8 for better compatibility with other tools
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Jun 13, 2024
1 parent 906a217 commit 9085123
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import imgviz
import natsort
import numpy as np
from qtpy import QtCore
from qtpy import QtGui
from qtpy import QtWidgets
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion labelme/label_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 9085123

Please sign in to comment.