@@ -482,7 +482,7 @@ class KeypointsAnnotation(Annotation):
482
482
label (str): The label for this annotation.
483
483
keypoints (List[:class:`Keypoint`]): The list of keypoints objects.
484
484
names (List[str]): A list that corresponds to the names of each keypoint.
485
- skeleton (List[List[int]]): A list of 2-length lists indicating a beginning and ending
485
+ skeleton (Optional[ List[List[int] ]]): A list of 2-length lists indicating a beginning and ending
486
486
index for each line segment in the skeleton of this keypoint label.
487
487
reference_id (str): User-defined ID of the image to which to apply this
488
488
annotation.
@@ -502,8 +502,8 @@ class KeypointsAnnotation(Annotation):
502
502
label : str
503
503
keypoints : List [Keypoint ]
504
504
names : List [str ]
505
- skeleton : List [List [int ]]
506
505
reference_id : str
506
+ skeleton : Optional [List [List [int ]]] = None
507
507
annotation_id : Optional [str ] = None
508
508
metadata : Optional [Dict ] = None
509
509
track_reference_id : Optional [str ] = None
@@ -524,29 +524,37 @@ def __post_init__(self):
524
524
seen .add (name )
525
525
526
526
max_segment_index = len (self .keypoints ) - 1
527
- for segment in self .skeleton :
528
- if len (segment ) != 2 :
529
- raise ValueError (
530
- "The keypoints skeleton must contain a list of line segments with exactly 2 indices"
531
- )
532
- for index in segment :
533
- if index > max_segment_index :
527
+
528
+ if self .skeleton is not None :
529
+ for segment in self .skeleton :
530
+ if len (segment ) != 2 :
534
531
raise ValueError (
535
- f "The skeleton index { index } is not a valid keypoint index "
532
+ "The keypoints skeleton must contain a list of line segments with exactly 2 indices "
536
533
)
534
+ for index in segment :
535
+ if index > max_segment_index :
536
+ raise ValueError (
537
+ f"The skeleton index { index } is not a valid keypoint index"
538
+ )
537
539
if self .annotation_id is None :
538
540
self .annotation_id = f"{ self .label } -{ self .reference_id } -keypoints"
539
541
540
542
@classmethod
541
543
def from_json (cls , payload : dict ):
542
544
geometry = payload .get (GEOMETRY_KEY , {})
545
+ skeleton = (
546
+ geometry [KEYPOINTS_SKELETON_KEY ]
547
+ if KEYPOINTS_SKELETON_KEY in geometry
548
+ else None
549
+ )
550
+
543
551
return cls (
544
552
label = payload .get (LABEL_KEY , 0 ),
545
553
keypoints = [
546
554
Keypoint .from_json (_ ) for _ in geometry .get (KEYPOINTS_KEY , [])
547
555
],
548
556
names = geometry [KEYPOINTS_NAMES_KEY ],
549
- skeleton = geometry [ KEYPOINTS_SKELETON_KEY ] ,
557
+ skeleton = skeleton ,
550
558
reference_id = payload [REFERENCE_ID_KEY ],
551
559
annotation_id = payload .get (ANNOTATION_ID_KEY , None ),
552
560
metadata = payload .get (METADATA_KEY , {}),
0 commit comments