Skip to content

Commit

Permalink
fix: update to export RLE mask with the shape of (width, height) order
Browse files Browse the repository at this point in the history
Signed-off-by: ktro2828 <[email protected]>
  • Loading branch information
ktro2828 committed Jan 30, 2025
1 parent 1634f14 commit ab2ff9c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions perception_dataset/deepen/segmentation/painting2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def from_file(

# Load mask from .npy
mask: NDArray = np.load(ann_info.mask)
mask = mask.reshape((height, width))
mask = mask.reshape((width, height))

# Get sensor ID
sensor_id = f"sensor{camera2index[ann_info.camera_name]}"
Expand Down Expand Up @@ -172,7 +172,7 @@ def _mask_to_instances(
"""Return a set of boxes and masks of each instance.
Args:
mask (NDArray): Mask array.
mask (NDArray): Mask array in the shape of (W, H).
id2category (Dict[int, str]): Key-value mapping of category ID and its name.
Returns:
Expand Down
8 changes: 5 additions & 3 deletions perception_dataset/deepen/segmentation/polygon2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ def _rle_from_polygons(polygons: Polygons2DLike, width: int, height: int) -> Dic
flattened = [[coord for point in polygon for coord in point] for polygon in polygons]

rle_objects = cocomask.frPyObjects(flattened, height, width)
rle = cocomask.merge(rle_objects)
rle_hw = cocomask.merge(rle_objects)

rle["counts"] = base64.b64encode(rle["counts"]).decode("ascii")
mask_hw = cocomask.decode(rle_hw)
rle_wh = cocomask.encode(np.asfortranarray(mask_hw.T))
rle_wh["counts"] = base64.b64encode(rle_wh["counts"]).decode("ascii")

return rle
return rle_wh
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def _rle_from_points(points: Points2DLike, width: int, height: int) -> Dict[str,
combined_mask = combined_mask - hollow_mask
final_mask = np.maximum(final_mask, combined_mask)
# encode RLE
rle = cocomask.encode(np.asfortranarray(np.squeeze(final_mask)))
rle = cocomask.encode(np.asfortranarray(np.squeeze(final_mask).T))
rle["counts"] = base64.b64encode(rle["counts"]).decode("ascii")
return rle

Expand Down

0 comments on commit ab2ff9c

Please sign in to comment.