1111import cv2
1212import numpy as np
1313import torch
14- from datumaro .components .annotation import Ellipse , Image , Mask , Polygon
14+ from datumaro .components .annotation import Bbox , Ellipse , Image , Mask , Polygon , RotatedBbox
1515from torchvision import tv_tensors
1616
1717from otx .core .data .dataset .base import Transforms
@@ -99,11 +99,11 @@ def _extract_class_mask(item: DatasetItem, img_shape: tuple[int, int], ignore_in
9999 raise ValueError (msg , ignore_index )
100100
101101 # fill mask with background label if we have Polygon/Ellipse annotations
102- fill_value = 0 if isinstance (item .annotations [0 ], (Ellipse , Polygon )) else ignore_index
102+ fill_value = 0 if isinstance (item .annotations [0 ], (Ellipse , Polygon , Bbox , RotatedBbox )) else ignore_index
103103 class_mask = np .full (shape = img_shape [:2 ], fill_value = fill_value , dtype = np .uint8 )
104104
105105 for mask in sorted (
106- [ann for ann in item .annotations if isinstance (ann , (Mask , Ellipse , Polygon ))],
106+ [ann for ann in item .annotations if isinstance (ann , (Mask , Ellipse , Polygon , Bbox , RotatedBbox ))],
107107 key = lambda ann : ann .z_order ,
108108 ):
109109 index = mask .label
@@ -112,7 +112,7 @@ def _extract_class_mask(item: DatasetItem, img_shape: tuple[int, int], ignore_in
112112 msg = "Mask's label index should not be None."
113113 raise ValueError (msg )
114114
115- if isinstance (mask , (Ellipse , Polygon )):
115+ if isinstance (mask , (Ellipse , Polygon , Bbox , RotatedBbox )):
116116 polygons = np .asarray (mask .as_polygon (), dtype = np .int32 ).reshape ((- 1 , 1 , 2 ))
117117 class_index = index + 1 # NOTE: disregard the background index. Objects start from index=1
118118 this_class_mask = cv2 .drawContours (
@@ -193,8 +193,8 @@ def __init__(
193193 @property
194194 def has_polygons (self ) -> bool :
195195 """Check if the dataset has polygons in annotations."""
196- ann_types = { str ( ann_type ). split ( "." )[ - 1 ] for ann_type in self . dm_subset . ann_types ()}
197- if ann_types & {"polygon" , "ellipse" }:
196+ # all polygon-like format should be considered as polygons
197+ if { ann_type . name for ann_type in self . dm_subset . ann_types ()} & {"polygon" , "ellipse" , "bbox" , "rotated_bbox " }:
198198 return True
199199 return False
200200
0 commit comments