Skip to content

Commit 3e799a7

Browse files
authored
Throw error if index in skeleton is greater than number of keypoints (#318)
* Throw error if index in skeleton is greater than number of keypoints * Update CHANGELOG
1 parent ae5d1e1 commit 3e799a7

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to the [Nucleus Python Client](https://github.com/scaleapi/n
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.13.5](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.13.4) - 2022-06-15
9+
10+
### Fixed
11+
- Guard against invalid skeleton indexes in KeypointsAnnotation
12+
813
## [0.13.4](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.13.4) - 2022-06-09
914

1015
### Fixed

nucleus/annotation.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ class KeypointsAnnotation(Annotation):
439439
label="face",
440440
keypoints=[Keypoint(100, 100), Keypoint(120, 120), Keypoint(visible=False), Keypoint(0, 0)],
441441
names=["point1", "point2", "point3", "point4"],
442-
skeleton=[[0, 1], [1, 2], [1, 3], [2, 4]],
442+
skeleton=[[0, 1], [1, 2], [1, 3], [2, 3]],
443443
reference_id="image_2",
444444
annotation_id="image_2_face_keypoints_1",
445445
metadata={"face_direction": "forward"},
@@ -486,11 +486,17 @@ def __post_init__(self):
486486
)
487487
seen.add(name)
488488

489+
max_segment_index = len(self.keypoints) - 1
489490
for segment in self.skeleton:
490491
if len(segment) != 2:
491492
raise ValueError(
492493
"The keypoints skeleton must contain a list of line segments with exactly 2 indices"
493494
)
495+
for index in segment:
496+
if index > max_segment_index:
497+
raise ValueError(
498+
f"The skeleton index {index} is not a valid keypoint index"
499+
)
494500

495501
@classmethod
496502
def from_json(cls, payload: dict):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ exclude = '''
2121

2222
[tool.poetry]
2323
name = "scale-nucleus"
24-
version = "0.13.4"
24+
version = "0.13.5"
2525
description = "The official Python client library for Nucleus, the Data Platform for AI"
2626
license = "MIT"
2727
authors = ["Scale AI Nucleus Team <nucleusapi@scaleapi.com>"]

0 commit comments

Comments
 (0)