Skip to content

Commit a503930

Browse files
committed
added max auto-clip range
1 parent 459cdaa commit a503930

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

luxonis_ml/data/datasets/annotation.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,17 @@ class BBoxAnnotation(Annotation):
145145
def validate_values(cls, values: Dict[str, Any]) -> Dict[str, Any]:
146146
warn = False
147147
for key in ["x", "y", "w", "h"]:
148+
if values[key] < -2 or values[key] > 2:
149+
raise ValueError(
150+
"BBox annotation has value outside of automatic clipping range ([-2, 2]). "
151+
"Values should be normalized based on image size to range [0, 1]."
152+
)
148153
if not (0 <= values[key] <= 1):
149154
warn = True
150155
values[key] = max(0, min(1, values[key]))
151156
if warn:
152157
logger.warning(
153-
"BBox annotation has values outside of [0,1] range. Clipping them to [0,1]."
158+
"BBox annotation has values outside of [0, 1] range. Clipping them to [0, 1]."
154159
)
155160
return values
156161

@@ -192,6 +197,13 @@ class KeypointAnnotation(Annotation):
192197
def validate_values(cls, values: Dict[str, Any]) -> Dict[str, Any]:
193198
warn = False
194199
for i, keypoint in enumerate(values["keypoints"]):
200+
if (keypoint[0] < -2 or keypoint[0] > 2) or (
201+
keypoint[1] < -2 or keypoint[1] > 2
202+
):
203+
raise ValueError(
204+
"Keypoint annotation has value outside of automatic clipping range ([-2, 2]). "
205+
"Values should be normalized based on image size to range [0, 1]."
206+
)
195207
new_keypoint = list(keypoint)
196208
if not (0 <= keypoint[0] <= 1):
197209
new_keypoint[0] = max(0, min(1, keypoint[0]))
@@ -203,7 +215,7 @@ def validate_values(cls, values: Dict[str, Any]) -> Dict[str, Any]:
203215

204216
if warn:
205217
logger.warning(
206-
"Keypoint annotation has values outside of [0,1] range. Clipping them to [0,1]."
218+
"Keypoint annotation has values outside of [0, 1] range. Clipping them to [0, 1]."
207219
)
208220
return values
209221

@@ -382,6 +394,11 @@ class PolylineSegmentationAnnotation(SegmentationAnnotation):
382394
def validate_values(cls, values: Dict[str, Any]) -> Dict[str, Any]:
383395
warn = False
384396
for i, point in enumerate(values["points"]):
397+
if (point[0] < -2 or point[0] > 2) or (point[1] < -2 or point[1] > 2):
398+
raise ValueError(
399+
"Polyline annotation has value outside of automatic clipping range ([-2, 2]). "
400+
"Values should be normalized based on image size to range [0, 1]."
401+
)
385402
new_point = list(point)
386403
if not (0 <= point[0] <= 1):
387404
new_point[0] = max(0, min(1, point[0]))
@@ -393,7 +410,7 @@ def validate_values(cls, values: Dict[str, Any]) -> Dict[str, Any]:
393410

394411
if warn:
395412
logger.warning(
396-
"Polyline annotation has values outside of [0,1] range. Clipping them to [0,1]."
413+
"Polyline annotation has values outside of [0, 1] range. Clipping them to [0, 1]."
397414
)
398415
return values
399416

0 commit comments

Comments
 (0)